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

How do I configure Vim's built-in file explorer netrw to look like a sidebar?

Answer

let g:netrw_liststyle=3 and let g:netrw_banner=0

Explanation

How it works

Vim ships with a built-in file explorer called netrw that you can access with :Explore (or :Ex). By default it looks plain, but with a few configuration variables you can make it behave like a modern file tree sidebar without any plugins.

Key netrw variables:

  • g:netrw_liststyle - Controls the display format
    • 0 = Thin listing (one file per line, default)
    • 1 = Long listing (with file size and timestamp)
    • 2 = Wide listing (multiple files per line)
    • 3 = Tree listing (with collapsible directories)
  • g:netrw_banner - The info banner at the top
    • 0 = Hide the banner
    • 1 = Show the banner (default)
  • g:netrw_winsize - Width of netrw window as percentage
    • 25 = 25% of screen width
  • g:netrw_browse_split - How to open files
    • 0 = Open in same window
    • 1 = Open in horizontal split
    • 2 = Open in vertical split
    • 3 = Open in new tab
    • 4 = Open in previous window

You can open netrw as a sidebar with :Lexplore (left explorer) which stays open as you browse files.

Example

Add to your ~/.vimrc:

let g:netrw_liststyle = 3
let g:netrw_banner = 0
let g:netrw_winsize = 25
let g:netrw_browse_split = 4
let g:netrw_altv = 1

Now open the sidebar with :Lexplore and you get a tree view:

project/
| src/
| | main.py
| | utils.py
| tests/
| | test_main.py
| README.md

Press Enter on a file to open it in the previous window. Press Enter on a directory to expand or collapse it. This gives you a NERDTree-like experience with zero plugins. Toggle the sidebar with :Lexplore again to close it.

Next

How do you yank a single word into a named register?