editing
.
Repeats the last CHANGE (any command that modified the buffer, including the whole insert-mode session that followed it). The single most-loved Vim feature — learn to structure edits so that '.' does the work for the next N occurrences.
. (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 3. | Repeat last change 3 times |
| n. | Powerful search-and-repeat idiom: find next match then re-apply the change |
Examples
cw hello<Esc>... Change one word to hello, then repeat on next 3 words with .
*cgnfoo<Esc>... Search for word, change to foo, then . on each next hit
dd. Delete this line, then delete another one
Gotcha
. only repeats CHANGES, not motions or searches — jkjk cannot be repeated with dot. Also, it uses the last register used, not always what you expect after a paste.
Related
u / Ctrl-R
u undoes the last change; Ctrl-R redoes it. Vim has a full undo TREE (see :undolist and g-/g+) but for day-to-day work these two keys are enough.
n / N
n jumps to the next match of the last search, N to the previous. Direction is relative to the ORIGINAL search direction — if you searched with ?, then n goes backward.
dd
Deletes the current line (and stores it in the unnamed register, so you can paste it back with p). The bread-and-butter 'get rid of this line' command.
i / a / o / O
The four ways to enter insert mode: i inserts BEFORE the cursor, a inserts AFTER it, o opens a new line BELOW and enters insert mode, O opens a new line ABOVE. Choosing the right one saves a motion or two before you start typing.
yy
'Yank' (copy) the current line into the unnamed register — Vim's word for copy. Combine with p/P to duplicate lines without touching your system clipboard.