nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 371feb7e540afc1d25c3369d4157358d21f51681
parent 42455176896560bf8cf7fc8457232131231b358f
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date:   Wed, 16 Oct 2019 13:26:20 -0400

Support tab-specific CWDs (#1032)

* Change CWD when switching tabs to the tab's NERDTree root.

* Remove commented-out code.

* List the new possible value for NERDTreeChDirMode in doc.

* Add new option to select between `:cd` and `:tcd`.

* Document the new NERDTreeUseTCD option.

* Update version number in change log.

Diffstat:
MCHANGELOG.md | 2++
Mdoc/NERDTree.txt | 16+++++++++++++---
Mlib/nerdtree/nerdtree.vim | 2+-
Mlib/nerdtree/path.vim | 9+++++++--
Mplugin/NERD_tree.vim | 7+++++++
5 files changed, 30 insertions(+), 6 deletions(-)
diff --git 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
@@ -849,9 +849,17 @@ above nodes would then be sorted like this: >
     z110.txt
 <
 ------------------------------------------------------------------------------
-                                                             *NERDTreeChDirMode*
+                                                                *NERDTreeUseTCD*
+Values: 0 or 1.
+Default: 0.
+
+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.
 
-Values: 0, 1 or 2.
+------------------------------------------------------------------------------
+                                                             *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
@@ -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
@@ -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
@@ -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)