6

How can you auto refresh the directory panes automatically in vim NERDTree? I know you can press R to refresh manually but I want to have it refresh automatically. This is particularly helpful when checking out between different git branches.

1
  • 2
    Refreshing “automatically” could mean when the file system fires a change event, or every X seconds, or whenever you re-focus Vim after having used a different application to edit files. Vim doesn’t directly support the first two events, but the last one is the autocommand FocusGained. – Rory O'Kane Nov 26 '14 at 12:12
4

For anyone seeing this on 2016, this worked for me:

autocmd CursorHold,CursorHoldI * call NERDTreeFocus() | call g:NERDTree.ForCurrentTab().getRoot().refresh() | call g:NERDTree.ForCurrentTab().render() | wincmd w

Enjoy!

0
3

Great NERD tree question. I googled and found related questions on monitoring real time changes and this one on NerdTree refresh. NERD tree has a built in cache.

UPDATE: following those links and combining the ideas the following put into your .vimrc should refresh every four seconds though an if statement to check for an open NERDTree might be in order too.

set autoread
au CursorHold * if exists("t:NerdTreeBufName") | call <SNR>15_refreshRoot() | endif

note: still a work in progress. My script number 15 was found using :scriptnames and looking up NERD_Tree.vim. Now to automate that part...

6
  • Depending on how the git checkout is done, the checkout might be used to initiate a refresh. – grantbow Sep 22 '14 at 17:33
  • 1
    Thanks but this did not work. vim says NERDTreeMapRefreshRoot is invalid – The Gripmaster Sep 27 '14 at 10:44
  • @the-gripmaster not an editor command? I fixed it with the g: prefix. – grantbow Sep 29 '14 at 20:51
  • 1
    Thanks. No more errors. But I don't see any auto refresh. I will try will a fresh .vimrc and keep you updated. – The Gripmaster Sep 30 '14 at 23:25
  • 1
    To automate calling refreshRoot() so it always works, without depending on :scriptnames output, I think the best thing would be to edit the NERDTree source to expose that function as a command :NERDTreeRefreshRoot. If that command works for you, you could then request that your changes be merged into the main NERDTree. – Rory O'Kane Nov 26 '14 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.