3

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 Answer 1

6

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.

2
  • 1
    I wouldn't be so harsh about this very useful option. I use it with 100+ plugins without problems. You're right, however, that for this particular use case, the autocmd emulation would be beneficial (though in this primitive form, it has other shortcomings...) Commented Nov 28, 2014 at 10:09
  • @IngoKarkat: Fair enough. Personally, I'd be annoyed if pwd changed except by my own action, so this is obviously not well tested. :)
    – Amadan
    Commented Nov 28, 2014 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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