diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 6ba9ee6..36e71ec 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -142,18 +142,9 @@ function! s:chRoot(node) endfunction " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1 -" changes the current root to CWD +" Change the NERDTree root to match the current working directory. function! nerdtree#ui_glue#chRootCwd() - try - let cwd = g:NERDTreePath.New(getcwd()) - catch /^NERDTree.InvalidArgumentsError/ - call nerdtree#echo("current directory does not exist.") - return - endtry - if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str() - return - endif - call s:chRoot(g:NERDTreeDirNode.New(cwd, b:NERDTree)) + NERDTreeCWD endfunction " FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1 diff --git a/doc/NERDTree.txt b/doc/NERDTree.txt index a83c4e1..278eb6c 100644 --- a/doc/NERDTree.txt +++ b/doc/NERDTree.txt @@ -142,8 +142,8 @@ The following features and functionality are provided by the NERD tree: current tab does not exist, a new one will be initialized. :NERDTreeCWD *:NERDTreeCWD* - Change tree root to current directory. If no NERD tree exists for this - tab, a new tree will be opened. + Change the NERDTree root to the current working directory. If no + NERDTree exists for this tab, a new one is opened. ------------------------------------------------------------------------------ 2.2. Bookmarks *NERDTreeBookmarks* @@ -522,7 +522,7 @@ Default key: cd Map option: NERDTreeMapChdir Applies to: files and directories. -Change vims current working directory to that of the selected node. +Change Vim's current working directory to that of the selected node. ------------------------------------------------------------------------------ *NERDTree-CD* @@ -530,7 +530,7 @@ Default key: CD Map option: NERDTreeMapCWD Applies to: no restrictions. -Change tree root to vims current working directory. +Change the NERDTree root to Vim's current working directory. ------------------------------------------------------------------------------ *NERDTree-I* diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 71d719a..2abd248 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -202,8 +202,28 @@ function! NERDTreeFocus() endfunction function! NERDTreeCWD() + + if empty(getcwd()) + call nerdtree#echoWarning('current directory does not exist') + return + endif + + try + let l:cwdPath = g:NERDTreePath.New(getcwd()) + catch /^NERDTree.InvalidArgumentsError/ + call nerdtree#echoWarning('current directory does not exist') + return + endtry + call NERDTreeFocus() - call nerdtree#ui_glue#chRootCwd() + + if b:NERDTree.root.path.equals(l:cwdPath) + return + endif + + let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree) + call b:NERDTree.changeRoot(l:newRoot) + normal! ^ endfunction function! NERDTreeAddPathFilter(callback)