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.
This commit is contained in:
Phil Runninger 2019-10-16 13:26:20 -04:00 committed by GitHub
parent 4245517689
commit 371feb7e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)