Skip to content

Lesson 1 of 9 · 22m

Operators and Motions: Vim Is a Language

The core editing grammar — verb plus object — and why memorizing keystrokes is the wrong way to learn Vim.

Vim feels cryptic when you learn it as a pile of commands. It becomes obvious when you learn it as a language: operator + motion. You do not memorize dw, ci", and yap as separate spells. You learn a small set of verbs, a small set of nouns, and combine them.

The grammar

[operator][count][motion or text object]
[count][operator][motion or text object]

d3w    delete three words forward
ci"    change inside the surrounding double quotes
yap    yank around the current paragraph

The main operators are:

  • d delete
  • c change (delete, then insert)
  • y yank (copy)
  • > / < indent / outdent
  • = reindent
  • gq format
  • gu / gU lowercase / uppercase

Once you know ci", you also know di", yi", gUi", and >i". That is the leverage.

Motions move; text objects select structure

Motions describe movement: w word, b back, $ end of line, } next paragraph, % matching bracket. Text objects describe structure and mostly start with i (inside) or a (around):

iw / aw   word
is / as   sentence
ip / ap   paragraph
i" / a"   quoted string
i( / a(   parenthesized region
it / at   XML/HTML tag

The difference matters. With the cursor inside print("debug", value), ci" changes the contents of one quoted string, while ca( changes the entire argument list including the parentheses. Reach for text objects before reaching for repeated w.

Change beats delete-plus-insert

c is the operator professionals use constantly because it preserves intent. ct: means “change until the next colon”; ci' means “replace this string”; c$ means “change to end of line.” The text is removed and insert mode starts in one atomic operation. Then . can repeat the entire replacement somewhere else.

Counts are precision, not ceremony

3dw and d3w usually mean the same thing, but counts compose awkwardly with visual selections and macros. Prefer the object-first phrasing you can read aloud: “delete three words” is d3w; “change inside quotes” is ci". If you need counts everywhere, you are often missing a better text object.

Field notes

  • Do not count characters. Use f, t, or a text object; character-counted edits break the moment the line changes.
  • f jumps onto a character, t jumps before it. ct) commonly means “change everything up to, but not including, the closing paren.”
  • The dot command repeats the last change, not the last motion. Moving with j does not overwrite what . repeats.
  • If an edit feels like five keystrokes of micro-movement, stop and name the object. There is usually a text object for it.

Was this lesson helpful?

Sign in to rate