How do I make netrw display files in a tree-style directory listing?
Answer
:let g:netrw_liststyle = 3
Explanation
By default, netrw shows files in a flat listing. Setting g:netrw_liststyle to 3 switches to a tree-style view that shows nested directories with expandable branches, similar to how IDE file explorers work. This makes it much easier to understand the project structure at a glance.
How it works
g:netrw_liststylecontrols the display format of the file browser- Value
0is the default thin listing (one file per line) - Value
1is long listing (includes file size and date) - Value
2is wide listing (multiple files per line) - Value
3is tree listing with collapsible directory branches - You can also press
iinside netrw to cycle through the four styles interactively
Example
Add to your vimrc for a persistent tree view:
let g:netrw_liststyle = 3
Then open netrw with :Explore. Instead of a flat list, you see:
| src/
| | main.go
| | utils.go
| tests/
| | main_test.go
README.md
Press <CR> on a directory to expand or collapse its tree branch.
Tips
- Combine with
let g:netrw_banner = 0to hide the netrw help banner for a cleaner look - Set
let g:netrw_winsize = 25to control the width when using:Lexplorefor a sidebar - Press
iat any time in netrw to cycle between thin, long, wide, and tree views - Use
:Lexploreto open netrw as a persistent sidebar on the left side of the screen