Vim's dot command: repeat any change
GoByte Skills #26: Vim remembers your last change as keystrokes, and . replays them at the cursor. Motions are not recorded, so shape the change to carry its own position: A, not $a. One key of automation, no YAML.
Zoe is one of GoByte's characters. This post was drafted by AI agents in Zoe's voice, then fact checked, run and edited by the GoByte team.
A change is a repeatable unit, and the dot key replays the last one anywhere, so shape the change to be repeatable. Vim keeps the keys of the last change: an operator with its motion (dw), or an insert from the key that started it to <Esc>, typed text included. . feeds those keys again at the cursor.
Transcript
One change, appending a semicolon with A, is recorded on the first line of a buffer, then the cursor moves down with j and the dot key replays the same change on the next two lines.
printf 'let a = 1\nlet bb = 22\nlet c = 3\n' > t.txt
vim -Nu NONE -n -es \
-c 'exe "normal ggA;\<Esc>j.j."' -c wq t.txt
cat t.txt
# let a = 1;
# let bb = 22;
# let c = 3;
A;<Esc> is the change. j is a motion, not a change, so it is never recorded and . keeps meaning "append a semicolon".
Shape it to travel#
The change must carry its own position. $a;<Esc> puts the semicolon in the right place once, but $ is a separate motion, so . replays only a; wherever j left the cursor. Same file, line 2 is longer:
keys: gg$a;<Esc>j.j.
let a = 1;
let bb = 2;2
let c = 3;
A is $a fused into one command, so it travels. The same logic picks ciw over cw: ciw replaces the whole word from anywhere inside it. Pair it with * (find the word under the cursor) and n. to rename one hit at a time, skipping the ones you want to keep.
Counts#
After 2dw, a bare . deletes two more words. 3. deletes three: a count on dot replaces the original one.
The boundary#
- An arrow key in Insert mode ends the change.
A1<Left>2<Esc>then.repeats only the2. - Ex commands are not changes. After
:s/a/b/,.replays your last Normal mode change instead. Repeat a substitution with&on this line, org&on every line.
Rule of thumb#
Before an edit, spend half a second asking whether . could do the next one. A instead of $a costs nothing now and pays every time you press dot. It is the cheapest automation you will ever write: one key, no YAML.
Your product here? Partner with us
Back to topDiscussion
No comments yet. Signed in GoByte members with a verified e-mail can join. Community guidelines
Reading is open to everyone. Commenting and voting need a GoByte account with a verified e-mail.