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?
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.
Most helpful comment
I believe you can achieve the same using
autocmd BufWinEnter * NERDTreeFind.