I have a secret, and it's time I aired it: I love Netrw, the file browser that comes packaged with Vim. It's great for browsing remote filesystems without leaving Vim and ditching your precious buffer list, but I use it even on my local machine. Local browsing is a large enough topic so it's all I'm going to talk about here. I never touch mc or ranger, and don't bother with other plugins like CtrlP because I fear excess plugins, which has something to do with why I like the BBQ. I don't bring in Python and Ruby hooks, vim-pathogen, whatever, I just install a minimal Vim package, set nocompatible, change out swapfiles for backups, and get on with life. In Netrw.
The two commands I make heavy use of:
:Explore sends you to the directory of the current file (in a split if it has unwritten changes), and
:Rexplore sends you to the last directory you saw in Netrw, in case you've been buffer-hopping in the meantime. I nnoremap these, but I don't have a reasonable mneumonic so you might as well come up with your own. (Optionally,
:Hexplore and
:Vexplore will open Netrw in a split window, but I don't clutter my screen doing that when a simple
C-o will take me right back to my last file anyway if I have a change of heart.)
If you don't like the look of Netrw, try pressing
i a few times to cycle through styles. Set
g:netrw_liststyle in your vimrc for perpetuity.
Most navigating techniques from normal mode work in Netrw.
j,
5j,
z^,
PgUp,
/,
?,
n, whatever you're used to for getting around, they all still work the same. Except marks.
Some quick default keymappings to get you started:
- % opens a new file in the current directory. You're prompted for a name.
- mf marks a file
- md diffs 2 or 3 marked files
- me edits all marked files in new buffers
- mx prompts for a shell command to be executed on marked files
- u and U navigate backward and forward in your directory history, while - acts as your "cd .."
- mb bookmarks a directory. gb takes you to your most recently bookmarked directory. You can view all bookmarks with qb. Use the bookmark number as a prefix to go to that bookmark: for example, 3gb goes to bookmark 3. (Yes, this is inelegant. I find I don't need to make use of long-standing bookmarks often, much as I used to do in mc.)
- o and v open the file under your cursor in a horizontal or vertical split. Size of the split can be set with g:netrw_winsize
- gh toggles hidden files
:help netrw-browse-maps gives you the full list. Compression, ctags, sorting and reverse sorting, and so on.
Here are the only global settings I feel I need in my .vimrc:
Code: Select all
" Hide top banner. Supposedly a
" dangerous thing to do. Might not
" work on all machines.
let g:netrw_banner=0
" Use cache to speed up browsing on remote
" file systems only. Don't bother at home.
" Manual refresh: C-l.
let g:netrw_fastbrowse=1
" Naivgating to a new directory changes
" the current working directory.
let g:netrw_keepdir=0
" One file per line, no time stamp.
" View file info with qf
let g:netrw_liststyle=0
This covers a very small portion of Netrw, but I use this stuff all the time.
Also, hi, everyone.