Created
June 7, 2011 19:56
-
-
Save joepestro/1013011 to your computer and use it in GitHub Desktop.
Function for .vimrc to automatically cd to the root of current tab's NERDTree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! ChangeDirectoryToNERDTreeDir() | |
" fallback to parent directory | |
let s:path = expand("%:p:h") | |
" if NERDTree is present in this tab, cd to it: | |
if exists("g:NERDTreeDirNode.GetRootForTab().path._strForCd()") | |
let s:path = g:NERDTreeDirNode.GetRootForTab().path._strForCd() | |
endif | |
" don't do anything if we're restoring a session | |
if exists("g:SessionLoad") && g:SessionLoad == 1 | |
return | |
else | |
exe "cd" s:path | |
" echo s:path | |
endif | |
endfunction | |
au WinEnter * call ChangeDirectoryToNERDTreeDir() |
Whoops! Not sure how that was working for me, but I updated to use s:path now.
Also, I was getting errors when restoring from a session so there's an additional check for that as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
?
a:path
is readonly.and
ChangeDirectoryToNERDTreeDir()
does not have argumentpath
.did you run this?