In the buffer
You ran :s/http:/https:/ on the first line, then pressed j to move down. Before:
api_url = "https://api.example.com/v1"
cdn_url = "http://cdn.example.com/static"
^
auth_url = "http://auth.example.com/login"
docs_url = "http://docs.example.com/"
After typing @::
api_url = "https://api.example.com/v1"
cdn_url = "https://cdn.example.com/static"
^
auth_url = "http://auth.example.com/login"
docs_url = "http://docs.example.com/"
The substitution runs again, this time on the line under the cursor. Press j@@ and it runs on the third line too. The fourth line stays http because you never asked for it.
When you would reach for it
You ran an Ex command that did exactly what you wanted on one line, and now you need it on a few more lines that are not next to each other and do not share a pattern you could hand to :g. Retyping the command is slow and invites typos. Pressing : and <Up> works, but it is three keystrokes plus <CR> every time. @: replays the whole command line in two keys, wherever the cursor happens to be.
Gotchas
.does not repeat Ex commands. It repeats the last normal-mode change, and a:sis not one. If you press.after a substitution, vim repeats whatever you changed before it, or nothing.@:is the dot for the command line.- The range is stored as text, not as lines.
:.,+1s/old/new/replays relative to wherever the cursor is now, and fails withE16: Invalid rangeif that runs past the end of the file. An absolute range like:5dhits line 5 every time, no matter where you are. - A count repeats the command in place.
3@:runs it three times on the same line without moving, which is useful for:swithoutg(one more match per run) but surprising if you expected it to walk down three lines. - The
":register only stores a command line if you typed at least one character of it. Commands run entirely from a mapping, or passed withvim -c, leave it unchanged. If nothing qualifies, you getE30: No previous command line.
Variants
@@
Repeats the last register execution, so after one @: you can keep going with j@@, j@@, the same way you would with a macro.
:s/$/,/
j2@:
Appends a comma to the next line twice, since a count runs the command repeatedly without moving the cursor.
g&
For substitutions specifically: reruns the last :s on every line in the file with the same pattern and flags. Use it when you tried the substitution on one line and now want it everywhere.