Vim: How to synchronize NERDTree with current opened tab file path?

I'm not sure if there's a NERDTree-specific way to do that, but you can always configure Vim so that it sets the working directory to the current file's directory:

autocmd BufEnter * lcd %:p:h

Now all what you have to do after opening a file in a new tab is :NERDTreeToggle in the new tab itself.


I use the following mapping to view the current buffer in NERDTree:

 map <leader>r :NERDTreeFind<cr>

throw a % sign on the end like a boss

:NERDTree %

i have this in my .vimrc, it maps Ctrl+o to toggle nerdtree in the dir of the current buffer:

map <C-o> :NERDTreeToggle %<CR>