Vim: the parts worth remembering

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, right
  • w / b / e — next word / back a word / end of word
  • 0 / ^ / $ — start of line / first non-blank / end of line
  • gg / G — top / bottom of file
  • Ctrl-u / Ctrl-d — scroll half a page up / down
  • f{char} — jump to the next {char} on this line
  • /pattern — search; n / N for next / previous match

Editing

  • i / a — insert before / after the cursor; o / O — new line below / above
  • x — delete a character
  • d{motion} — delete (dw a word, dd a line)
  • c{motion} — change: delete, then drop into Insert mode
  • y{motion} — yank (copy); p — paste
  • u — 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.