2011-10-07 54 views

回答

137

在:H NERDTree:

: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. 

我不認爲它必將在默認情況下任何東西,所以你要做一個keybind自己。

nmap ,n :NERDTreeFind<CR> 

就是出現在我的.vimrc,與

nmap ,m :NERDTreeToggle<CR> 
+0

鍵映射的工作原理,但如何在VIM中調用NERDTreeFind? – toszter

+7

@toszter只是':NERDTreeFind' – Thomas

+0

有沒有辦法將它設置爲在該選項卡內創建NERDTree時執行此操作? –

7

看看這個一起,它可以自動同步操作,只要更改緩衝區,nerdtree會自動刷新自己(我從here複製有微小的修改)

" 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() 
+0

謝謝,我一直在尋找這個很長一段時間! :) – Gnagno