When I start neovim from my home directory, but pass an argument to a project folder, such as nvim ~/dev/my_project, the working directory is still in my home directory, and netrw shows all my home directory files.
How could I change this behavior, so neovim cd’s into the directory specified when starting neovim?
I have some scripts that gives a dir as argument to neovim/neovide.
It may be good to treat this in the autocmd to avoid always changing the cwd.
It can cause conflicts with sessions.
-- Assume that is a directory on the fs gived as argument
if vim.fn.argc() == 1 then
vim.api.nvim_create_autocmd("VimEnter", {
pattern = "*",
callback = function()
vim.api.nvim_set_current_dir(vim.fn.expand("%:p:h"))
end
})
end
Maybe there’s a better way to do this.
What we need to know is not to always change the value of cwd, it can cause problems with plugins that use this internal variable value.
When i run neovim/neovide inside or outside the terminal without arguments, it’s loading automatically my last session, regardless of the current dir that’s being executed. If i give the . operator or any path, the autocmd will be loaded as expected. The session plugin does not load the session as an argument to the executable, which is really cool. It can coexist with this autocmd for now…