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

How do I open a persistent file explorer sidebar using Vim's built-in netrw?

Answer

:Lexplore

Explanation

:Lexplore opens Vim's built-in netrw file explorer as a persistent sidebar anchored to the left of the screen. Unlike :Explore which replaces the current buffer, :Lexplore keeps the file tree visible as you open and navigate files — no plugins needed.

How it works

  • :Lexplore — open (or toggle) a left-side netrw window
  • :Lexplore {dir} — open the explorer starting in a specific directory
  • :Rexplore — return focus to the explorer from an open file
  • Pressing <CR> on a file opens it in the adjacent editing window while the sidebar stays open
  • Running :Lexplore again closes the sidebar (toggle behavior)

Example

:Lexplore

A narrow file tree opens on the left. Navigate with j/k, enter directories with <CR>, go up with -, and open files. The sidebar persists across file changes.

Tips

  • Control the sidebar width: let g:netrw_winsize = 25 in your vimrc (percentage of screen)
  • Switch to tree view: let g:netrw_liststyle = 3 for an indented directory tree
  • Toggle hidden files with gh inside netrw
  • :Lexplore stores the window so :Rexplore can always return you to it
  • For a right-side panel, use :Rexplore (right explore) or set g:netrw_altv = 1

Next

How do I comment out all lines matching a pattern at once using vim-commentary?