vimtricks.wiki Concise Vim tricks, one at a time.

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_liststyle controls the display format of the file browser
  • Value 0 is the default thin listing (one file per line)
  • Value 1 is long listing (includes file size and date)
  • Value 2 is wide listing (multiple files per line)
  • Value 3 is tree listing with collapsible directory branches
  • You can also press i inside 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 = 0 to hide the netrw help banner for a cleaner look
  • Set let g:netrw_winsize = 25 to control the width when using :Lexplore for a sidebar
  • Press i at any time in netrw to cycle between thin, long, wide, and tree views
  • Use :Lexplore to open netrw as a persistent sidebar on the left side of the screen

Next

How do I display the full absolute path of the current file in Vim?