-1

I have let g:NERDTreeChDirMode=3 and expect nvim ~/Projects/foo to run nvim with :pwd set to ~/Projects/foo. But instead it has :pwd set to my home directory from which I am running it. As a result when I go to file in NERDTree view, file content replaces NERDTree view, and if I then do NERDTreeToggle, it has root in the home directory instead of project directory.

Is it possible to pass directory to Vim and automatically cd into it and has NERDTree root there ?

EDIT: https://github.com/preservim/nerdtree/issues/1191

1
  • Shell: (cd ~/Projects/foo && nvim) aka pushd ~/Projects/foo && nvim && popd
  • As arguments: nvim +'cd $HOME/Projects/foo' (you can use 'execute "cd" expand("~/Projects/foo")' too but that's more verbose IMO)
  • Depending on how your shell quotes and expands, you might be able to do nvim +'cd '~/Projects/foo (if the path doesn't have any spaces in it on shells that care about that)

If you want something more automatic, you'll need to write an autocommand (probably on VimEnter) to check the number of arguments and :cd to (e.g.) the first one.

1
  • Not quite what I've expected, but thanks for information) – vatosarmat Dec 23 '20 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.