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:
: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.
:Lexplore which toggles netrw in a split, that saves me having to switch to and close the netrw window.
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
let g:netrw_list_hide = '^\.\.\=/\=$,.DS_Store,.idea,.git,__pycache__,venv,node_modules,*\.o,*\.pyc,.*\.swp' let g:netrw_hide = 1
Opening files can be handled in different ways using the
1open file in new horizontal split
2open file in new vertical split
3open file in new tab
4open 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
The file list and directory expanding/collapsing are configured using
1list files with file info on the right
2list files horizontally and down
3list files with expandable directories
4list 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
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
: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.