Skip to content
Browse files

Merge pull request #204 from techlivezheng/feature/chrootcwd

Add a NERDTreeCWD command to change tree root to CWD
  • Loading branch information...
2 parents dff80ff + 072d468 commit 1dc3891f960c25aa3f23aa46f5afc8d41db38233 @scrooloose committed Nov 12, 2012
Showing with 38 additions and 0 deletions.
  1. +13 −0 doc/NERD_tree.txt
  2. +25 −0 plugin/NERD_tree.vim
View
13 doc/NERD_tree.txt
@@ -137,6 +137,10 @@ The following features and functionality are provided by the NERD tree:
In any case, the current file is revealed and the cursor is placed on it.
+:NERDTreeCWD *:NERDTreeCWD*
+ Change tree root to current directory. If no NERD tree exists for this
+ tab, a new tree will be opened.
+
------------------------------------------------------------------------------
2.2. Bookmarks *NERDTreeBookmarks*
@@ -247,6 +251,7 @@ r.......Recursively refresh the current directory................|NERDTree-r|
R.......Recursively refresh the current root.....................|NERDTree-R|
m.......Display the NERD tree menu...............................|NERDTree-m|
cd......Change the CWD to the dir of the selected node...........|NERDTree-cd|
+CD......Change tree root to the CWD..............................|NERDTree-CD|
I.......Toggle whether hidden files displayed....................|NERDTree-I|
f.......Toggle whether the file filters are used.................|NERDTree-f|
@@ -515,6 +520,14 @@ Applies to: files and directories.
Change vims current working directory to that of the selected node.
------------------------------------------------------------------------------
+ *NERDTree-CD*
+Default key: CD
+Map option: NERDTreeMapCWD
+Applies to: no restrictions.
+
+Change tree root to vims current working directory.
+
+------------------------------------------------------------------------------
*NERDTree-I*
Default key: I
Map option: NERDTreeMapToggleHidden
View
25 plugin/NERD_tree.vim
@@ -140,6 +140,7 @@ call s:initVariable("g:NERDTreeMapToggleHidden", "I")
call s:initVariable("g:NERDTreeMapToggleZoom", "A")
call s:initVariable("g:NERDTreeMapUpdir", "u")
call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U")
+call s:initVariable("g:NERDTreeMapCWD", "CD")
"SECTION: Script level variable declaration{{{2
if s:running_windows
@@ -171,6 +172,7 @@ command! -n=1 -complete=customlist,s:completeBookmarks -bar NERDTreeFromBookmark
command! -n=0 -bar NERDTreeMirror call s:initNerdTreeMirror()
command! -n=0 -bar NERDTreeFind call s:findAndRevealPath()
command! -n=0 -bar NERDTreeFocus call NERDTreeFocus()
+command! -n=0 -bar NERDTreeCWD call NERDTreeCWD()
" SECTION: Auto commands {{{1
"============================================================
augroup NERDTree
@@ -2943,6 +2945,8 @@ function! s:createDefaultBindings()
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapQuit, 'scope': "all", 'callback': s."closeTreeWindow" })
+ call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCWD, 'scope': "all", 'callback': s."chRootCwd" })
+
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefreshRoot, 'scope': "all", 'callback': s."refreshRoot" })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefresh, 'scope': "Node", 'callback': s."refreshCurrent" })
@@ -3327,6 +3331,11 @@ function! NERDTreeFocus()
endif
endfunction
+function! NERDTreeCWD()
+ call NERDTreeFocus()
+ call s:chRootCwd()
+endfunction
+
" SECTION: View Functions {{{1
"============================================================
"FUNCTION: s:centerView() {{{2
@@ -3467,6 +3476,7 @@ function! s:dumpHelp()
let @h=@h."\" ". g:NERDTreeMapMenu .": Show menu\n"
let @h=@h."\" ". g:NERDTreeMapChdir .":change the CWD to the\n"
let @h=@h."\" selected dir\n"
+ let @h=@h."\" ". g:NERDTreeMapCWD .":change tree root to CWD\n"
let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Tree filtering mappings~\n"
@@ -4077,6 +4087,21 @@ function! s:chRoot(node)
call b:NERDTreeRoot.putCursorHere(0, 0)
endfunction
+" FUNCTION: s:chRootCwd() {{{2
+" changes the current root to CWD
+function! s:chRootCwd()
+ try
+ let cwd = s:Path.New(getcwd())
+ catch /^NERDTree.InvalidArgumentsError/
+ call s:echo("current directory does not exist.")
+ return
+ endtry
+ if cwd.str() == s:TreeFileNode.GetRootForTab().path.str()
+ return
+ endif
+ call s:chRoot(s:TreeDirNode.New(cwd))
+endfunction
+
" FUNCTION: s:clearBookmarks(bookmarks) {{{2
function! s:clearBookmarks(bookmarks)
if a:bookmarks ==# ''

0 comments on commit 1dc3891

Please sign in to comment.
Something went wrong with that request. Please try again.