:NERDTreeFind :NERDTreeFind
Find the current file in the tree. If no tree exists for the current tab,
or the file is not under the current root, then initialize a new tree where
the root is the directory of the current file.
" Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()
" Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()
function! ToggleNerdTree()
set eventignore=BufEnter
NERDTreeToggle
set eventignore=
endfunction
nmap <C-n> :call ToggleNerdTree()<CR>
" Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
function! CheckIfCurrentBufferIsFile()
return strlen(expand('%')) > 0
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && CheckIfCurrentBufferIsFile() && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufRead * call SyncTree()
function! ToggleTree()
if CheckIfCurrentBufferIsFile()
if IsNERDTreeOpen()
NERDTreeClose
else
NERDTreeFind
endif
else
NERDTree
endif
endfunction
" open NERDTree with ctrl + n
nmap <C-n> :call ToggleTree()<CR>