How to expand directories by default in Vim’s netrw tree view

vimvimrc

I can make netrw use the tree view by default by adding this to my vimrc:

let g:netrw_liststyle=3

But I can't figure out how to expand sub-directories by default, is there a way?

Best Answer

Reading all subdirectories would be a costly operation, and slow down the opening of netrw considerably. As the tree display is just one (non-default) mode of several display modes, that's probably the reason why there's no such command. I tried something like this (triggering the <Enter> mapping on each directory line to open it):

:global/^│ /exe "normal \<CR>"

But it unfortunately didn't work.

Plugin alternative

The NERDTree plugin is similar to netrw, but it is built around a tree-style display (in a sidebar). As such, it also has commands to open subtrees (but those are just as slow as with netrw).