oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

feature request: Allow moving file into a new directory when the name contains a slash

Open titouancreach opened this issue 1 year ago • 18 comments

Did you check existing requests?

  • [X] I have searched the existing issues

Describe the feature

I have a file like:

foobar.js

if I rename the file to

hello/foobar.js

I'd like to create a directory hello and put foobar.js in it

Provide background

No response

Additional details

If it's a feature you may like, ~i can write a PR~

titouancreach avatar May 31 '23 12:05 titouancreach

This is a neat idea, but it's more complicated than it first seems. The main issue is the possibility that hello/foobar.js or even just hello/ already exist. It's doable, but I'll have to be real careful about the edge cases.

I'll keep this on the back burner until I get the time to look deeper into it.

stevearc avatar Jun 17 '23 01:06 stevearc

+1 for this one!

I've been using oil.nvim for quite a while already and absolutely love it! I think this feature will kind of complete all the flow that typically happens when editing/creating files/folders.

rasulomaroff avatar Sep 04 '23 21:09 rasulomaroff

Another fun complication :) -- move file to parent directory by renaming it ../file.txt or ./../file.txt. For some reason this (as well as subdirectories) feels very intuitive for me in the context of the rest of oil.nvim's features.

NReilingh avatar Sep 04 '23 22:09 NReilingh

Another fun complication :) -- move file to parent directory by renaming it ../file.txt or ./../file.txt. For some reason this (as well as subdirectories) feels very intuitive for me in the context of the rest of oil.nvim's features.

Absolutely! Or moving it into a directory inside a parent one by ../dir/file.txt

rasulomaroff avatar Sep 05 '23 10:09 rasulomaroff

another one (for fun): transforming a file to a folder if the file is empty and without extension. Use case: I create a foobar file: hoo noo, i wanted to create a folder but I created an extensionless file instead, rename to foobar/

titouancreach avatar Sep 05 '23 12:09 titouancreach

if the file is empty and without extension

I think that doesn't really necessary. Directories with dots are perfectly valid. Alternatively, if a file is not empty and you are transforming it into a directory, then this information can easily be shown in the confirmation window.

But I would go with any way @stevearc decides to implement, if he does.

rasulomaroff avatar Sep 05 '23 19:09 rasulomaroff

@titouancreach congratulations, your pain is also my pain! And that's a much easier fix, so I've gone ahead and implemented it. Now you can change a file to a dir or vice-versa by adding/removing the trailing /. It'll translate that change to a delete + create.

For the other requests in this issue, I'm still looking into it. I have some ideas and a rough plan now, but I just haven't had the unbroken time to sit down and hash it out.

stevearc avatar Sep 11 '23 01:09 stevearc

Great job @stevearc ! I update my packages right now !

titouancreach avatar Sep 11 '23 07:09 titouancreach

Just discovered Oil and love it so far, but this is definitely one of the things I'm hoping gets added. Currently my solution is to continue using telescope file browser to handle moving files between directories, but I'd definitely LOVE to be able to do that in Oil :)

LittleTealeaf avatar Nov 25 '23 15:11 LittleTealeaf

Hey pal! Love the plugin a ton. Totally heard on the complexities involved in this feature request, too. I'm here because I also just attempted to do this intuitive feeling ask, and the operation of course failed.

Let me know if there's anything I can do to help you with this feature. Thanks for an amazing project!

augustdolan avatar Dec 02 '23 14:12 augustdolan

Loving this plugin and I'm feeling the same way as those above. Would be a great addition to this awesome package.

danrasmuson avatar Jan 31 '24 15:01 danrasmuson

Hello, sorry but I have not understood the whole discussion, I would like to kindly ask if it currently possible to automatically create missing folders during file operation.

If still not possible, I agree this would be a must-have feature (if feasible).

pidgeon777 avatar Feb 02 '24 14:02 pidgeon777

Made a PR which I think works for all the cases I can think of. Let me know if I missed anything!

pi314ever avatar Feb 06 '24 07:02 pi314ever

This is working great for me! Thank you!

danrasmuson avatar May 10 '24 19:05 danrasmuson

moving files into the parent directory using ../file_name.txt still doesn't work, are there any plans for implementing this? I really enjoy oil but being able to move things to the parent directory is quite important to me when I am refactoring things. For now I am gonna have to use @pi314ever fork as that feature works there.

ruigouveiamaciel avatar May 17 '24 09:05 ruigouveiamaciel

Hi, moving a file to an existed folder doesn't work for me, either. Just as below, I want to move auto-session.lua to archive/auto-session.lua, but it prompted that Filename cannot contain path separator. if I rewrite the whole line to archive/auto-session.lua regardless of the icon at the beginning then it will just create a blank new file istead of moving file. I really like oil and reply on it heavily. Please correct me if I've got it wrong. If the feature does miss for the moment, hope that we could consider to add it in the near future. Thank you in advance. image

swahpy avatar May 24 '24 14:05 swahpy

Hi, moving a file to an existed folder doesn't work for me, either. Just as below, I want to move auto-session.lua to archive/auto-session.lua, but it prompted that Filename cannot contain path separator. if I rewrite the whole line to archive/auto-session.lua regardless of the icon at the beginning then it will just create a blank new file istead of moving file. I really like oil and reply on it heavily. Please correct me if I've got it wrong. If the feature does miss for the moment, hope that we could consider to add it in the near future. Thank you in advance. image

Yep, same thing still happening

oxi1224 avatar Jul 08 '24 11:07 oxi1224

For anyone still having this issue, my suggestion is to simply delete the file you want to move with dd (do not save the deletion), then move into the folder you want to move the file into, paste the deleted file and then Save. It will prompt you to move the file.

ruigouveiamaciel avatar Jul 09 '24 10:07 ruigouveiamaciel

This is a neat idea, but it's more complicated than it first seems. The main issue is the possibility that hello/foobar.js or even just hello/ already exist. It's doable, but I'll have to be real careful about the edge cases.

I think it might be useful to cover the most simple and unambiguous case first: if the folder does not exists and there are no duplicated files when trying to move, then it can be created and al the files moved at once. It seems "future-proof" enough, so more complex edge cases might be treated in the future. In my case, this would be enough most of the times.

akiross avatar Oct 14 '24 12:10 akiross

I think it might be useful to cover the most simple and unambiguous case first: if the folder does not exists and there are no duplicated files when trying to move, then it can be created and al the files moved at once. It seems "future-proof" enough, so more complex edge cases might be treated in the future. In my case, this would be enough most of the times.

I agree. That would greatly improve its usability.

ndavd avatar Oct 14 '24 13:10 ndavd