CodeRigor

FREE LESSON

Vim operators: d c y with motions, counts and .

Combine operators with motions, repeat them with counts and the dot command.

Most edits are operator + motion:

Operator Does
d delete
c change (delete, then insert)
y yank (copy)

dw deletes a word, c$ changes to the end of the line, y2j yanks three lines. Doubling an operator acts on whole lines: dd, cc, yy. Shortcuts: D = d$, C = c$, x = dl, s = cl.

p puts after the cursor (below, for lines); P before.

Counts go before the command or the motion: 3dw = d3w.

Compose a counted edit: 3dw
start / 3
A count, an operator and a motion form one change. Here, delete over three word motions; dot can repeat that change.
Compose a counted edit: 3dw
A count, an operator and a motion form one change. Here, delete over three word motions; dot can repeat that change.

The dot command

. repeats the last change — including everything you typed in insert mode. Make a change once, move, press .. It's the single most useful key in Vim.

Text
cwfoo<Esc>    change a word to foo
w.            next word: change it too

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Vim as a language of operators (verbs) and motions/text objects (nouns) — the idea behind d, c, y.