: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>
6条答案
按热度按时间q7solyqu1#
在:h NERDTree中:
我认为默认情况下它没有绑定到任何东西,所以你必须自己进行键绑定。
是出现在我的.vimrc中的内容,沿着
ddarikpa2#
看看这个,它自动化同步操作,每当你改变缓冲区,nerdtree将自动刷新自己(我从here复制微小的修改)
vlf7wbxs3#
这也可能只是一个注解。在当前版本中,切换NerdTree并使用SyncTree会导致NERDTree被调用两次。此修改似乎解决了该问题:
fxnxkyjh4#
陈如山的回答+注解对我来说非常好用,除了当树打开时。有了这个设置,当树打开时,树中的当前文件将显示出来。
owfi6suc5#
要沿着陈如山的帖子,那
我不会让NERDTree关闭。我找不到一个解决方案(除了下面的),可以在允许NERDTree切换的同时突出显示当前打开的缓冲区。
下面是我拼凑起来的,以便在使用
Ctrl + ]
进行下一个缓冲区Map时能够切换NERDTree并突出显示文件。希望其他人能改进这一点。
k5ifujac6#