diff --git a/CHANGELOG.md b/CHANGELOG.md index f79be93..73d17b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) --> +#### 6.2 +- **.0**: Support tab-specific CWDs (PhilRunninger) [#1032](https://github.com/scrooloose/nerdtree/pull/1032) #### 6.1 - **.4**: Add VIM built-in package management to read me file. (pesarkhobeee) [#1049](https://github.com/scrooloose/nerdtree/pull/1049) - **.3**: Save/Set screen state also on WinLeave and WinEnter. (PhilRunninger) [#1048](https://github.com/scrooloose/nerdtree/pull/1048) diff --git a/doc/NERDTree.txt b/doc/NERDTree.txt index 14f7078..32b0b5d 100644 --- a/doc/NERDTree.txt +++ b/doc/NERDTree.txt @@ -849,9 +849,17 @@ above nodes would then be sorted like this: > z110.txt < ------------------------------------------------------------------------------ - *NERDTreeChDirMode* + *NERDTreeUseTCD* +Values: 0 or 1. +Default: 0. -Values: 0, 1 or 2. +By default, NERDTree will use the `:cd` command to change the current working +directory. If this setting is turned on, and the `:tcd` command is available, it +will be used instead. + +------------------------------------------------------------------------------ + *NERDTreeChDirMode* +Values: 0, 1, 2, or 3. Default: 0. Use this setting to tell the script when (if at all) to change the current @@ -871,6 +879,9 @@ the CWD is changed whenever the tree root is changed. For example, if the CWD is /home/marty/foobar and you make the node for /home/marty/foobar/baz the new root then the CWD will become /home/marty/foobar/baz. +If the set to 3, then it behaves the same as if set to 2, and the CWD is +changed whenever changing tabs to whatever the tree root is on that tab. + ------------------------------------------------------------------------------ *NERDTreeHighlightCursorline* Values: 0 or 1. @@ -980,7 +991,6 @@ then (to single click activate it) you must click somewhere in ------------------------------------------------------------------------------ *NERDTreeQuitOnOpen* - Values: 0,1,2 or 3. Default: 0 diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index a12eb36..3e7ade8 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -20,7 +20,7 @@ function! s:NERDTree.changeRoot(node) call self.root.open() "change dir to the dir of the new root if instructed to - if g:NERDTreeChDirMode ==# 2 + if g:NERDTreeChDirMode >= 2 call self.root.path.changeToDir() endif diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index d00bb89..ccb9423 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -87,8 +87,13 @@ function! s:Path.changeToDir() endif try - execute "cd " . dir - call nerdtree#echo("CWD is now: " . getcwd()) + if g:NERDTreeUseTCD && exists(":tcd") == 2 + execute "tcd " . dir + call nerdtree#echo("Tab's CWD is now: " . getcwd()) + else + execute "cd " . dir + call nerdtree#echo("CWD is now: " . getcwd()) + endif catch throw "NERDTree.PathChangeError: cannot change CWD to " . dir endtry diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 40609f0..5faebaa 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -48,6 +48,7 @@ call s:initVariable("g:NERDTreeAutoCenterThreshold", 3) call s:initVariable("g:NERDTreeCaseSensitiveSort", 0) call s:initVariable("g:NERDTreeNaturalSort", 0) call s:initVariable("g:NERDTreeSortHiddenFirst", 1) +call s:initVariable("g:NERDTreeUseTCD", 0) call s:initVariable("g:NERDTreeChDirMode", 0) call s:initVariable("g:NERDTreeCreatePrefix", "silent") call s:initVariable("g:NERDTreeMinimalUI", 0) @@ -183,6 +184,12 @@ if g:NERDTreeHijackNetrw augroup END endif +if g:NERDTreeChDirMode == 3 + augroup NERDTreeChDirOnTabSwitch + autocmd TabEnter * if g:NERDTree.ExistsForTab()|call g:NERDTree.ForCurrentTab().getRoot().path.changeToDir()|endif + augroup END +endif + " SECTION: Public API {{{1 "============================================================ function! NERDTreeAddMenuItem(options)