I found out that when I change directory with :cd
, the root directory of NerdTree is not affected. How can I make NerdTree change its root when I use :cd
?
1 Answer
I believe your best bet is to utilize the command :NERDTreeCWD
:
:NERDTreeCWD *:NERDTreeCWD*
Change the NERDTree root to the current working directory. If no
NERDTree exists for this tab, a new one is opened.
Now you can't override :cd
but you could create a custom command that's close...it just has to start with a capital letter:
:com! -nargs=1 -bar -complete=dir Cd :cd <args> | NERDTreeCWD
Use just like :cd
...
:Cd /some/path
Never mind all that...this just occurred to me and is much better IMO.
There is an auto command event triggered by directory change
augroup DIRCHANGE
au!
autocmd DirChanged global :NERDTreeCWD
augroup END
That's it.
Note that this is only for the global directory change of :cd
. To have this work with :lcd
you'd change global
to window
or you could include both by separating them with commas. Full list:
"window" to trigger on `:lcd`
"tabpage" to trigger on `:tcd`
"global" to trigger on `:cd`
"auto" to trigger on 'autochdir'.
"drop" to trigger on editing a file
-
1