Personal Notes on 'Practical Vim' (2nd Edition)
I went through “Practical Vim - Second Edition” by Drew Neil and wrote down the parts I keep coming back to. Mostly for my own reference, but maybe useful to someone else.
Navigation
H,M,L: jump to the top, middle, and bottom of the screen.
Buffers
:lslists open buffers.%marks the active one.:bnext,:bprevious,:bfirst,:blastmove between them.
Mappings I use (from Tim Pope’s unimpaired.vim):
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :blast<CR>
Windows and tabs
:sp[lit]/:vsp[lit]split the current window.:split {file}and:vsplit {file}open a file in a new split.Ctrl-w w/h/j/k/lswitches between windows.:clo[se]closes a window,:on[ly]closes all but the current one.Ctrl-w =/_/|resizes.:tabe {file}opens a file in a new tab. Navigate with:tabn,:tabp,gt,gT.:tabmove nreorders tabs.
I think of tabs as workspaces (one per task or context) and windows as views within a workspace.
Jumps and marks
:jumpsshows your jump history.Control-ogoes back,Control-igoes forward.m{a-z}sets a mark,\{a-z}` jumps to it. Useful for bouncing between two spots in a file.
Macros
q{a-z}records a macro,@{a-z}plays it back.@@repeats the last one.- You can run a macro on a range of lines:
:5,10normal @a. - Combine with
:let i += 1for numbered sequences.
Macros are one of those Vim features that feel clunky until they save you 20 minutes on a mechanical edit.
Search and replace
/\cmakes a search case insensitive.\vturns on “very magic” mode (closer to normal regex).\Vdoes a literal search, no regex interpretation.- Leaving the search pattern empty in
:s//replacement/reuses the last search, which is handy for iterating.
.vimrc
A few things I added to mine:
- Leader key:
let mapleader = "," - Autosave on leaving insert mode:
autocmd InsertLeave,TextChanged * silent write - Auto-indent on save:
autocmd BufWritePre * :normal gg=G
TLDR
“Practical Vim” covers a lot that’s easy to miss. These are the parts I actually use.