Sometimes I run a complicated search-and-replace (
:s/../../) in Vim, and I then want to repeat it somewhere else. In the past, I have always hit
:, up-arrow to retrieve the command from the history. It should be no surprise by now that there is an easier way!
@: in normal mode (at-sign, colon) will repeat the last
: command. Once you have done
@:, you can hit
@@ to re-run the command. Quick and easy!
This works because the
":, holds the last Ex command.
@ runs a macro, and knows that using the
: register means you want to repeat an Ex command.
@@ runs the last macro, so works for
@: just as it does for
@a or any other normal-mode macro.
:help registers when I was looking for a register that held the filename of the file open in another window, as opposed to the alternate filename in the current window. Details of
": are at
:help ": (believe it or not! 😉 ).