NERDTree reload new files
Asked Answered
E

5

250

If I add a file to the same directory opened in NERDTree, the only way I can see the file added is if I quit vim and start it again .

Is there a way I can reload the files in NERDTree?

Engrave answered 9/1, 2012 at 18:45 Comment(0)
T
430

You could close and reopen NERDTree or simply hit r to refresh the current directory's listing or R to refresh the root directory's listing .

Do you see "Press ? for help" at the top of the NERDTree window? It means that you can press ? for help. If you do, you will see an exhaustive listing of NERDTree shortcuts. That's neat.

More generally, many plugins have a thorough documentation that you can access with :help <pluginame>.

Tallbot answered 9/1, 2012 at 20:6 Comment(6)
closing and re-opening NERDTree doesn't work ... r works ! Thanks !Engrave
Re-opening it didn't work because NERDTree caches the directory listing. You can see a message to that effect when refreshing with 'r'.Archaimbaud
I'd looked over the ? help three times and never saw r!Grant
Indeed, the NERDTree help window does not list the r shortcutUltimate
The NERDTree ? quickhelp does list these shortcuts, in its “Filesystem mappings” section. It lists “r: refresh cursor dir” and “R: refresh current root”.Unlay
Upvoted for Do you see "Press ? for help"? It means that you can press ? for help.Bully
A
24

As @romainl answered above; press r to refresh current directory or R to refresh root directory.

You can consider adding new files from nerdTree itself by pressing m, then a to add a new file (or directory by adding a trailing slash). This way you don't need to refresh nerdTree to see the new added file.

Annadiane answered 1/4, 2015 at 8:57 Comment(0)
B
11

Refresh NERDTree

Instead of hitting R in the NERDTree window, I use a custom map that does it for me:

nmap <Leader>r :NERDTreeRefreshRoot

I've mapped it to Leader + r, but you can map it to whatever you want.


Explanation:

  • It first switches to the NERDTree window
  • Then refreshes the Root Node (by simulating the R key)
  • And finally switches back to the previous window

Note: You can add a last step to refresh CtrlP along with NERDTree

Bainite answered 22/10, 2016 at 21:35 Comment(1)
You can map to :NERDTreeRefreshRoot without focusing tree.Accession
B
6

You can hit R button by using feedkeys function. Just like this:

call feedkeys("R")  

I have defined a function in my .vimrc file:

fun! ToggleNERDTreeWithRefresh()
    :NERDTreeToggle 
    if(exists("b:NERDTreeType") == 1)
        call feedkeys("R")  
    endif   
endf 

nmap <silent> <c-l> :call ToggleNERDTreeWithRefresh()<cr>  

So, when I type ctrl+l, the NERDTree will be toggled and refresh root directory.

Bogard answered 10/11, 2016 at 6:10 Comment(0)
T
3

Personally I prefer to trigger the refresh automatically when focusing the NERDTree window. This autocommand (in your .vimrc) will do it

autocmd BufEnter NERD_tree_* | execute 'normal R'

Thigh answered 24/1, 2021 at 20:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.