Learn Practice Daily golf Reference

How to repeat the last command in Vim

In Normal mode, press . to repeat your last change. To repeat the last command you typed after a colon, press @:; after that, @@ repeats it again.

Try it here

Tidy a function with the dot

Add a space after the first comma with f, and a Esc, then ; jumps to the next comma and . adds the same space. Then A;Esc ends the next line, and j. j. ends the two after it.

1 of 3f, then a, space, Esc; then ; and .
1function invite(name,email,role) {
1 const user = lookup(email)
2 const team = user.team
3 return send(user, team, role)
4}
NORMALLoading the editor…1/30.0s1:1

This editor needs a keyboard. Read on, and play it at your computer.

KeysRepeats
.the last change: a delete, a change, an insert, an indent, a paste
3.the last change with a new count (after dd, 3. deletes three lines)
@:the last command typed after :
@@the last @: (or macro) again
&the last :s substitute, on the current line, without its flags
:&& ↵the last :s on the current line, with its flags
g&the last :s on every line in the file, with its flags, using the last search pattern
; / ,the last f, t, F or T jump, forwards / backwards
n / Nthe last search, the same way / the other way
: then ↑brings back earlier colon commands to run again or edit

What the dot repeats

. repeats the last command that changed the text: x, dd, dw, >>, p, or an insert from the key that started it to the Esc that ended it, text included. So A;Esc once, then j. on every other line, is the whole job.

It does not repeat moves, searches, undo, or colon commands; that is why each of those has its own repeat key. The habit that makes . pay is to make the change in a way that works again elsewhere: A rather than $a, ciw rather than cw from the middle of a word, cgn rather than cw after a search.

Repeating colon commands

@: runs the last command-line command again, wherever the cursor is now, and takes a count: 3@: runs it three times. After one @:, @@ is the shorter way to say it again. To run an older command, type : and press ↑ to step back through the history (type the start of the command first, and ↑ only shows commands that start the same way).