@@ -140,6 +140,7 @@ call s:initVariable("g:NERDTreeMapToggleHidden", "I")
140
140
call s: initVariable (" g:NERDTreeMapToggleZoom" , " A" )
141
141
call s: initVariable (" g:NERDTreeMapUpdir" , " u" )
142
142
call s: initVariable (" g:NERDTreeMapUpdirKeepOpen" , " U" )
143
+ call s: initVariable (" g:NERDTreeMapCWD" , " CD" )
143
144
144
145
" SECTION: Script level variable declaration{{{2
145
146
if s: running_windows
@@ -171,6 +172,7 @@ command! -n=1 -complete=customlist,s:completeBookmarks -bar NERDTreeFromBookmark
171
172
command ! -n =0 - bar NERDTreeMirror call s: initNerdTreeMirror ()
172
173
command ! -n =0 - bar NERDTreeFind call s: findAndRevealPath ()
173
174
command ! -n =0 - bar NERDTreeFocus call NERDTreeFocus ()
175
+ command ! -n =0 - bar NERDTreeCWD call NERDTreeCWD ()
174
176
" SECTION: Auto commands {{{1
175
177
" ============================================================
176
178
augroup NERDTree
@@ -2943,6 +2945,8 @@ function! s:createDefaultBindings()
2943
2945
2944
2946
call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapQuit , ' scope' : " all" , ' callback' : s ." closeTreeWindow" })
2945
2947
2948
+ call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapCWD , ' scope' : " all" , ' callback' : s ." chRootCwd" })
2949
+
2946
2950
call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapRefreshRoot , ' scope' : " all" , ' callback' : s ." refreshRoot" })
2947
2951
call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapRefresh , ' scope' : " Node" , ' callback' : s ." refreshCurrent" })
2948
2952
@@ -3327,6 +3331,11 @@ function! NERDTreeFocus()
3327
3331
endif
3328
3332
endfunction
3329
3333
3334
+ function ! NERDTreeCWD ()
3335
+ call NERDTreeFocus ()
3336
+ call s: chRootCwd ()
3337
+ endfunction
3338
+
3330
3339
" SECTION: View Functions {{{1
3331
3340
" ============================================================
3332
3341
" FUNCTION: s:centerView() {{{2
@@ -3467,6 +3476,7 @@ function! s:dumpHelp()
3467
3476
let @h = @h ." \" " . g: NERDTreeMapMenu ." : Show menu\n "
3468
3477
let @h = @h ." \" " . g: NERDTreeMapChdir ." :change the CWD to the\n "
3469
3478
let @h = @h ." \" selected dir\n "
3479
+ let @h = @h ." \" " . g: NERDTreeMapCWD ." :change tree root to CWD\n "
3470
3480
3471
3481
let @h = @h ." \" \n \" ----------------------------\n "
3472
3482
let @h = @h ." \" Tree filtering mappings~\n "
@@ -4077,6 +4087,21 @@ function! s:chRoot(node)
4077
4087
call b: NERDTreeRoot .putCursorHere (0 , 0 )
4078
4088
endfunction
4079
4089
4090
+ " FUNCTION: s:chRootCwd() {{{2
4091
+ " changes the current root to CWD
4092
+ function ! s: chRootCwd ()
4093
+ try
4094
+ let cwd = s: Path .New (getcwd ())
4095
+ catch /^NERDTree.InvalidArgumentsError/
4096
+ call s: echo (" current directory does not exist." )
4097
+ return
4098
+ endtry
4099
+ if cwd.str () == s: TreeFileNode .GetRootForTab ().path .str ()
4100
+ return
4101
+ endif
4102
+ call s: chRoot (s: TreeDirNode .New (cwd))
4103
+ endfunction
4104
+
4080
4105
" FUNCTION: s:clearBookmarks(bookmarks) {{{2
4081
4106
function ! s: clearBookmarks (bookmarks)
4082
4107
if a: bookmarks == # ' '
0 commit comments