autochdir and NERDTree

2.8k views Asked by At

autochdir automatically sets the current working directory to the present file that the cursor is located on. I'd like to exclude autochdir from changing the directory if the cursor is in the NERDTree window.

For example, if the present file I'm working on is in ~/foo, and the NERDTree window is in ~/lots/of/stuff/here, I'd like to go to the NERDTree window and still have the current working directory set to ~/foo.

That way, one can apply the CD keybind, which will set NERDTree's root tree node to ~/foo. Otherwise, it's terribly inconvenient to manually change the root tree node in the NERDTree window by navigating to ~/foo, and then applying the cd keybind.

1

There are 1 answers

2
Amadan On BEST ANSWER

From :help autochdir:

This option is provided for backward compatibility with the Vim released with Sun ONE Studio 4 Enterprise Edition.
Note: When this option is on some plugins may not work.

I.e. it is obsolete, inflexible and breaks plugins. I suggest you don't use it, and instead use one of the alternate, more configurable mechanisms here. For instance,

autocmd BufEnter * if &ft !~ '^nerdtree$' | silent! lcd %:p:h | endif

However, while this does not change the current directory when you pull up NERDTree, it will not preserve it, either. I'm not 100% sure what you mean in your last paragraph.