How do I make Vim's built-in file explorer display files as a tree rather than a flat list?
Answer
:let g:netrw_liststyle=3
Explanation
Vim ships with a built-in file browser called netrw, opened with :Explore (or :Ex). By default it shows a flat directory listing, but setting netrw_liststyle to 3 switches it to a persistent tree view — similar to NERDTree — without any plugins.
How it works
g:netrw_liststylecontrols netrw's display mode- Style
0— thin listing (default) - Style
1— long listing (shows file size and date) - Style
2— wide listing (multiple columns) - Style
3— tree listing (nested directory tree) - You can also cycle through styles interactively with
iinside netrw
Example
Add to your vimrc:
let g:netrw_liststyle = 3
Then open netrw with :Ex or :Explore. The file tree expands as you navigate into directories, letting you browse multiple levels simultaneously.
Tips
- Press
iinside netrw to cycle through all four listing styles without editing your config :Vexplore(:Vex) opens netrw as a vertical split — combine withliststyle=3for a sidebar feel- Set
let g:netrw_winsize = 25to control the width of the netrw split (as a percentage) - Set
let g:netrw_banner = 0to hide the help banner at the top for a cleaner view - Press
-in any buffer to open netrw in the current file's directory