7

I know how to refresh NERDTree manually hitting R when focus is in the NERDTree column.

I would like this done automatically.

If an event is needed to trigger this, let it be "whenever writing a file".

Someone suggests adding this to vimrc

nmap <Leader>r :NERDTreeFocus<cr>R<c-w><c-p>

to map this to a key.

The solution could be a combination of this and autocmd.

Jérôme
  • 263
  • 4
  • 10

2 Answers2

3

Putting everything together, something like this would do:

autocmd BufWritePost * NERDTreeFocus | execute 'normal R' | wincmd p

You can add additional autocmd events. However, be aware that above doesn't handle the case when you're currently already in the NERDTree window (but this could be handled with a conditional on &filetype ==# 'nerdtree'). Then, this would also work on events such as CursorHold.

Ingo Karkat
  • 23,523
2

Personally I prefer to trigger the refresh automatically when focusing the NERDTree window. This autocommand will do it

autocmd BufEnter NERD_tree_* | execute 'normal R'

Patrick
  • 121