better solution with auto command
Source Link
B Layer
  • 17.8k
  • 1
  • 18
  • 51

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 changeauto 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 add another autocmd line if you wantedcould 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

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 add another autocmd line if you wanted both. Full list:

"window"  to trigger on `:lcd`
"tabpage" to trigger on `:tcd`
"global"  to trigger on `:cd`

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
better solution with auto command
Source Link
B Layer
  • 17.8k
  • 1
  • 18
  • 51

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

Alternatively, thereNever mind all that...this just occurred to me and is much better IMO.

There is an auto command event triggered by directory change which just occurred to me

augroup DIRCHANGE
    au!
    autocmd DirChanged global :NERDTreeCWD
augroup END

That's it. Stand by while I see what I can come up with with

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 add another autocmd line if you wanted both. Full list:)

It'll be something like

autocmd"window" DirChanged globalto trigger on `:NERDTreeCWDlcd`
"tabpage" to trigger on `:tcd`
"global"  to trigger on `:cd`

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

Alternatively, there is an auto command event triggered by directory change which just occurred to me. Stand by while I see what I can come up with with that. :)

It'll be something like

autocmd DirChanged global :NERDTreeCWD

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 add another autocmd line if you wanted both. Full list:

"window"  to trigger on `:lcd`
"tabpage" to trigger on `:tcd`
"global"  to trigger on `:cd`
Source Link
B Layer
  • 17.8k
  • 1
  • 18
  • 51

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

Alternatively, there is an auto command event triggered by directory change which just occurred to me. Stand by while I see what I can come up with with that. :)

It'll be something like

autocmd DirChanged global :NERDTreeCWD