Nerdtree: Synchronize nerdtree highlight with buffer switch.

Created on 13 Jul 2012  路  2Comments  路  Source: preservim/nerdtree

Is there a way nerdtree can auto-sync with buffer switch? I can do it manually with nnoremap ,i :NERDTreeFind<CR><c-w><c-w> but I am looking for auto-sync.

I dived into vim docs to look for events I can bind to, but BufRead gets called only once, when the file is read into the buffer; and BufEnter can't be used as everytime I enter the buffer, it will call NERDTreeToggle sending me back to nerd tree pane. Any ideas?

Most helpful comment

I believe you can achieve the same using autocmd BufWinEnter * NERDTreeFind.

All 2 comments

I mainly use bufexplorer for switching buffers. I solved my problem by hooking NERDTreeFind with bufexplorer.

function! ChangeBuffer()
    if bufwinnr(t:NERDTreeBufName) != -1
        exe "normal! :NERDTreeFind\<cr>\<c-w>\<c-w>"
    endif
endfunction
let g:BufExplorerFuncRef = function('ChangeBuffer')

I believe you can achieve the same using autocmd BufWinEnter * NERDTreeFind.

Was this page helpful?
0 / 5 - 0 ratings