Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: prefer creation of files over directories with :e in oil buffer #77

Closed
1 task done
mjlbach opened this issue Mar 17, 2023 · 3 comments · Fixed by #78
Closed
1 task done

feature request: prefer creation of files over directories with :e in oil buffer #77

mjlbach opened this issue Mar 17, 2023 · 3 comments · Fixed by #78
Labels
enhancement New feature or request

Comments

@mjlbach
Copy link

mjlbach commented Mar 17, 2023

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

I regularly use netrw with vinegar style bindings (- to go up). My default workflow for creating a new file in a given project is to open netrw, navigate to the directory I want, and :e %:p:h -> tab -> new filename.

Unfortunately, by default oil will open with a url of the form:
:e oil:///Users/michael/Repositories/fluffychat/macos

This means that if I append test.file I get
:e oil:///Users/michael/Repositories/fluffychat/macos/test.file

Which opens me in a new oil buffer, rather than a text buffer (accidentally wrote 20 new files instead of a 20 line file this way).

I'm not sure how to handle this (or I would have filed a PR), since there is not a good way to disambiguate between new file/folder by path alone, but I guess my expectation as a user with :e would be that the final path element would correspond to a new file.

Provide background

No response

Additional details

Love the plugin! If I was still a neovim dev I would tell you to upstream it and tear out netrw :)

@mjlbach mjlbach added the enhancement New feature or request label Mar 17, 2023
@mjlbach mjlbach changed the title feature request: allow creation of files with :e in oil buffer feature request: prefer creation of files over directories with :e in oil buffer Mar 17, 2023
@stevearc
Copy link
Owner

Hey, good to see you back in the vimscape!

I have two ideas for this. The first is pretty minimal: you could use a cabbr to replace % with the filepath.

vim.cmd.cabbr({ args = { "<expr>", "%", "&filetype == 'oil' ? bufname('%')[6:] : '%'" } })

It's not a drop-in replacement for your workflow, but you would at least be able to keep some of the same muscle memory.

The second idea is drafted in this PR: #78
The basic idea is to detect when a path like oil://path/to/file.txt is a normal file, and if so, open it as a normal buffer instead of an oil buffer. It's using vim.filetype.match() on the filename to detect if it's a normal file or not. It's a bit more involved, but should hopefully Just Work.

@mjlbach
Copy link
Author

mjlbach commented Mar 18, 2023

Hey, good to see you back in the vimscape!

Just visiting :)

I can definitely work around it. I just wanted to bring it to your attention :) I think #78 is an elegant solution, but totally your call if you don't want to add the complexity!

@stevearc
Copy link
Owner

Happy to merge #78! I'll just have to wrangle the CI tests into passing :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants