Skip to main content

Vim Commands That Compose: A Survival Guide and Vim Cheat Sheet

Stop fighting Vim. Learn the modes, motions, and verb+motion operators that compose, search and replace, and how to actually quit — with real commands you can copy.

Published By Li Lei
#vim #cheatsheet #developer-tools #terminal #productivity

Vim Commands That Compose: A Survival Guide and Vim Cheat Sheet

The first time Vim trapped me, I was three hours into a 2am deploy. git commit with no -m dropped me into a blank buffer over SSH, and I genuinely did not know how to get out. I closed the terminal tab. That, it turns out, is the single most-asked Vim question on Stack Overflow, and you are not the first to do it either.

Here is the thing nobody tells you on day one: Vim is not a list of 200 shortcuts to memorize. It is a tiny grammar. Once you stop treating it as a keymap and start treating it as a language, the whole thing collapses into something you can hold in your head. This guide walks the parts that actually matter — modes, motions, operators that compose, search and replace, and yes, how to quit — and points you at a full Vim cheat sheet when you need the rest.

Modes are the whole trick

Most editors have one mode: you type, text appears. Vim has several, and confusing them is why beginners feel like the keyboard is haunted.

You spend most of your time in normal mode, where every key is a command, not a character. Press i and you drop into insert mode, where typing works like any other editor. Press Esc and you are back in normal mode. There is also visual mode (v) for selecting text, and command mode (:) for the colon commands like :w to write.

Four keys get you through a panic: Esc, i, :, and :q. With those you can open a file, type into it, save, and quit. That is the survival kit. Everything else is upgrades.

Motions: moving without arrow keys

In normal mode your fingers stay on the home row. h j k l move left, down, up, right. The mnemonic that finally stuck for me: h is the leftmost of the four so it goes left, and j hangs down like a hook so it goes down.

But character-by-character movement is the beginner trap. The real motions jump:

  • w jumps forward one word, b jumps back, e to the end of a word
  • 0 goes to the start of the line, $ to the end, ^ to the first non-blank
  • gg goes to the top of the file, G to the bottom
  • f" jumps to the next " on the line; t( stops just before the next (
  • % jumps between matching brackets

You almost never want to hold down a key. You want to say where you are going.

Operators that compose: verb + motion

This is the idea that turns Vim from "weird editor" into "the editor." Commands are built from a verb and a motion, and they combine freely.

The three verbs you use constantly:

  • d — delete (it actually cuts)
  • c — change (delete, then drop into insert mode)
  • y — yank (copy)

Glue any of them to a motion and you get a precise edit:

  • dw deletes from the cursor to the start of the next word
  • d$ deletes to the end of the line
  • c$ changes to the end of the line
  • y0 yanks back to the start of the line
  • dgg deletes everything up to the top of the file

You do not memorize dw and cw and d$ as separate facts. You learn the verbs, you learn the motions, and the multiplication table writes itself. Double the verb to act on a whole line: dd deletes a line, yy copies one, cc changes one. The doubled letter is a consistent Vim pattern.

Then there are text objects, which read like English. iw is "inner word," i" is "inside the quotes," ap is "a paragraph." Pair them with a verb and you stop counting characters entirely.

A worked example: changing text inside quotes

Say you have this line and your cursor is sitting anywhere on it:

const title = "old heading text";

You want to replace what is between the quotes. The clumsy way is to navigate to the opening quote, delete to the closing quote, count, and retype. The Vim way is one command: ci".

Read it as "change inside quotes." The moment you press ci", Vim deletes everything between the double quotes — no matter where your cursor is on the line, no matter how long the string — and leaves you in insert mode ready to type. You type new heading, press Esc, and you have:

const title = "new heading";

Three keystrokes plus your new text. The same grammar gives you di( to empty a function's arguments, ca{ to replace a whole block including the braces, and yi[ to copy an array's contents. Once ci" clicks, you reach for the rest without thinking.

Search and replace

/pattern searches forward, ?pattern searches backward. After a search, n jumps to the next match and N to the previous. Land on a word and press * to search for the next occurrence of it instantly.

Substitution lives in command mode. The pattern is :s/old/new/ to swap the first match on the current line. The flags are what make it powerful:

  • :%s/old/new/g — replace every match in the whole file (% is "all lines," g is "every match on each line")
  • :%s/old/new/gc — same, but c makes Vim ask y/n at each spot

That c flag has saved me from more than one rename gone wrong. When a reviewer asks you to rename a variable across 40 lines, :%s/oldName/newName/gc walks you through every hit so you never clobber a substring you meant to keep. The regex you write here is standard-ish — if you want to push it further, our regex cheat sheet covers the lookaheads and character classes Vim's substitute accepts.

The dot command and macros

Press . and Vim repeats your last change. Change one word with cwnewName then Esc, jump to the next match with n, and tap . — the entire change replays. It is the lightweight cousin of a macro.

For bigger repetition, record a macro: qa starts recording into register a, you do the edits once, q stops. Then @a replays it, and 199@a runs it 199 times down a file. Reformatting 200 log lines that all need the same surgery goes from twenty minutes of hand edits to one recording and one playback.

How to actually quit

The part everyone googles. From normal mode (Esc first if you are unsure):

  • :w writes (saves) without quitting
  • :q quits — but refuses with E37: no write since last change if you have unsaved edits
  • :wq saves and quits
  • :q! quits and throws away changes
  • ZZ is a shortcut for save-and-quit; ZQ is quit-without-saving

E37 is not a sign you broke anything. It is Vim protecting your work. Add ! to force it, or :wq to keep your edits.

And if you ever dd something important by accident — dd cuts, it does not destroy. Press u to undo, or p to paste back what you just deleted.

Building the muscle memory

Nobody learns Vim by reading. You learn it by reaching for ci" instead of arrow-keying to the quote, feeling the friction of the old way, and letting the new way win. Start with the 15-command starter set — modes, basic motions, the three verbs — and add one new command a week when you hit a real annoyance. Learning macros before you have 200 lines to reformat is how people decide Vim is "too hard" and quit.

Keep the full Vim cheat sheet open in a tab while you build the habit. It is searchable, every command has a mnemonic, and it runs entirely in your browser. When you are ready for the rest of the daily syntax stack, the git cheat sheet pairs with it for the workflow that drops you into Vim in the first place.


Made by Toolora · Updated 2026-06-13