I watched the editors lecture from MIT's Missing Semester course. Its core argument: when programming, you spend more time reading and editing code than writing it, so it's worth using an editor built around editing — and that's Vim.
This isn't a full cheat sheet. It's the subset I actually want to remember.
(If you're starting from zero, run vimtutor first — it ships with Vim and
takes about 30 minutes.)
Modes
Vim is a modal editor — keys mean different things depending on which mode
you're in. <Esc> always brings you back to Normal mode, which is where you
spend most of your time.
| Mode | Enter with | For |
|---|---|---|
| Normal | <Esc> |
moving around, running commands |
| Insert | i |
actually typing text |
| Visual | v / V (line) |
selecting text |
| Command-line | : |
save, quit, substitute, ... |
The essentials: :w save, :q quit, :wq both, :q! quit without saving.
Moving around
Never hold an arrow key. There's almost always a motion that jumps straight to where you're looking.
h j k l— left, down, up, rightw/b/e— next word / back a word / end of word0/^/$— start of line / first non-blank / end of linegg/G— top / bottom of fileCtrl-u/Ctrl-d— scroll half a page up / downf{char}— jump to the next{char}on this line/pattern— search;n/Nfor next / previous match
Editing
i/a— insert before / after the cursor;o/O— new line below / abovex— delete a characterd{motion}— delete (dwa word,dda line)c{motion}— change: delete, then drop into Insert modey{motion}— yank (copy);p— pasteu— undo;Ctrl-r— redo
The part that made it click for me: these compose. Commands are verbs,
motions are nouns, and counts multiply — d2w deletes two words, ci(
changes everything inside the parentheses. Once you know a handful of verbs
and nouns, you get their combinations for free. The lecture calls this
"editing in a programming language", and it's the reason Vim keys are worth
learning at all.
Search and replace
:s is substitute, and it uses regex:
:s/old/new/— first match on the current line:s/old/new/g— all matches on the current line:%s/old/new/g— all matches in the whole file
Configuration
Vim out of the box is deliberately minimal, so a small vimrc fixes the sharp
edges — things like set incsearch to search as you type and disabling the
arrow keys so you actually learn the motions.
My vimrc is
commented and MIT-licensed — feel free to take it as a starting point. The setting choices
were informed by the lecture, which also walks through its own recommended
config.