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

How to prevent oil to edit nvim argv values ? #586

Closed
Kazppa opened this issue Feb 15, 2025 · 3 comments
Closed

How to prevent oil to edit nvim argv values ? #586

Kazppa opened this issue Feb 15, 2025 · 3 comments

Comments

@Kazppa
Copy link

Kazppa commented Feb 15, 2025

Sorry for this issue but I didn't find any existing one on this subject.

It seems oil.nvim is messing with the command line arguments and ends up editing vim.fn.argv values, replacing paths with something like "oil:///..." when I initially called "nvim ." from my terminal.

Is there a way to prevent this or to retrieve the actual arguments passed to the command line ?
This is messing with other plugins trying to parse the command line arguments.

@stevearc
Copy link
Owner

This is a fun Neovim bug. Try this

-- Save this as foo.lua
-- nvim foo.lua
-- :source
vim.api.nvim_buf_set_name(0, "bar.lua")
print(vim.inspect(vim.fn.argv()))

Renaming the buffer also changes the names of the args. Unfortunately we have to rename the buffer because oil relies on the fact that all oil buffers have a standard name format. You could try reporting this upstream; there's nothing we can do here.

@Kazppa
Copy link
Author

Kazppa commented Feb 16, 2025

Is there a magic function in oil to convert an oil name format to a normal file path ?

@stevearc
Copy link
Owner

stevearc commented Feb 16, 2025

You can use require("oil.util").parse_url(bufname). It will return the scheme + the path. Under the hood it's just doing a pattern match, which you could also take and do yourself

M.parse_url = function(url)
return url:match("^(.*://)(.*)$")
end

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

No branches or pull requests

2 participants