@@ -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
@@ -2936,6 +2938,8 @@ function! s:createDefaultBindings()
2936
2938
2937
2939
call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapQuit , ' scope' : " all" , ' callback' : s ." closeTreeWindow" })
2938
2940
2941
+ call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapCWD , ' scope' : " all" , ' callback' : s ." chRootCwd" })
2942
+
2939
2943
call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapRefreshRoot , ' scope' : " all" , ' callback' : s ." refreshRoot" })
2940
2944
call NERDTreeAddKeyMap ({ ' key' : g: NERDTreeMapRefresh , ' scope' : " Node" , ' callback' : s ." refreshCurrent" })
2941
2945
@@ -3305,6 +3309,11 @@ function! NERDTreeFocus()
3305
3309
endif
3306
3310
endfunction
3307
3311
3312
+ function ! NERDTreeCWD ()
3313
+ call NERDTreeFocus ()
3314
+ call s: chRootCwd ()
3315
+ endfunction
3316
+
3308
3317
" SECTION: View Functions {{{1
3309
3318
" ============================================================
3310
3319
" FUNCTION: s:centerView() {{{2
@@ -3445,6 +3454,7 @@ function! s:dumpHelp()
3445
3454
let @h = @h ." \" " . g: NERDTreeMapMenu ." : Show menu\n "
3446
3455
let @h = @h ." \" " . g: NERDTreeMapChdir ." :change the CWD to the\n "
3447
3456
let @h = @h ." \" selected dir\n "
3457
+ let @h = @h ." \" " . g: NERDTreeMapCWD ." :change tree root to CWD\n "
3448
3458
3449
3459
let @h = @h ." \" \n \" ----------------------------\n "
3450
3460
let @h = @h ." \" Tree filtering mappings~\n "
@@ -4055,6 +4065,21 @@ function! s:chRoot(node)
4055
4065
call b: NERDTreeRoot .putCursorHere (0 , 0 )
4056
4066
endfunction
4057
4067
4068
+ " FUNCTION: s:chRootCwd() {{{2
4069
+ " changes the current root to CWD
4070
+ function ! s: chRootCwd ()
4071
+ try
4072
+ let cwd = s: Path .New (getcwd ())
4073
+ catch /^NERDTree.InvalidArgumentsError/
4074
+ call s: echo (" current directory does not exist." )
4075
+ return
4076
+ endtry
4077
+ if cwd.str () == s: TreeFileNode .GetRootForTab ().path .str ()
4078
+ return
4079
+ endif
4080
+ call s: chRoot (s: TreeDirNode .New (cwd))
4081
+ endfunction
4082
+
4058
4083
" FUNCTION: s:clearBookmarks(bookmarks) {{{2
4059
4084
function ! s: clearBookmarks (bookmarks)
4060
4085
if a: bookmarks == # ' '
0 commit comments