Making netrw Clean and Minimally Disruptive. Then Stop Using It.

Before jumping to a project drawer/file browser plugin, let's make netrw clean and minimally disruptive. Then stop using it.

Making netrw Clean and Minimally Disruptive. Then Stop Using It.

Before jumping to a project drawer/file browser plugin, let's make netrw clean and minimally disruptive. Then stop using it.

If you open netrw with default settings, it might look something like this:

Simply using :Explore will open netrw in the current window. You can also use :Vexplore to open in a vertical split or :Hexplore to open in a horizontal split.

I use :Lexplore which toggles netrw in a split, that saves me having to switch to and close the netrw window.

Massive Header

The header has some useful information, but after seeing it once, I don't need that info again. Let's remove the header by adding this to vimrc:

let g:netrw_banner = 0

Hiding Dot Files and Others

Now I want to hide some dot files and other pesky directories like __pycache__.

let g:netrw_list_hide = '^\.\.\=/\=$,.DS_Store,.idea,.git,__pycache__,venv,node_modules,*\.o,*\.pyc,.*\.swp'
let g:netrw_hide = 1

Split Window

Opening files can be handled in different ways using the netrw_browse_split option:

  • 1 open file in new horizontal split
  • 2 open file in new vertical split
  • 3 open file in new tab
  • 4 open in previous window

Similar to project drawer plugins or common editors, opening in the previous window beside the split is my preference:

let g:netrw_browse_split = 4

List Style

The file list and directory expanding/collapsing are configured using netrw_liststyle:

  • 1 list files with file info on the right
  • 2 list files horizontally and down
  • 3 list files with expandable directories
  • 4 list files only (my favorite)

My Final Configuration

let g:netrw_banner = 0
let g:netrw_list_hide = '^\.\.\=/\=$,.DS_Store,.idea,.git,__pycache__,venv,node_modules,*\.o,*\.pyc,.*\.swp'
let g:netrw_hide = 1
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_liststyle = 4
let g:netrw_winsize = 20

I also have a shortcut to toggle netrw:

nnoremap <silent> ,e :Lexplore<cr>

Now by simply hitting ,e I can open and close quickly. (comma , is my mapleader)

Why you shouldn't use netrw

Now that netrw is configured to be clean and minimally invasive. I don't use it very often, if at all.

Vim has so many useful ways to search, open and manage buffers. Why scan through multiple directories searching for a file when you can just :find with tab completion and wildmenu.

Using :find is a must and now that you have all of your buffers open, :b will let you fuzzy search through the buffer list making it even faster to flip to different open files. It's all based on fuzzy search, no more digging through directories and cycling through tabs.