2/15/2025
You can record macros in vim.
-
qq
to start recording into register q. -
q
to stop recording. -
@q
to play the macro from register q.
But that last step can be called while recording.
-
qq
to start recording into register q. -
@q
to call the macro you are now recording. -
q
to stop recording. -
@q
to play the macro from register q.
Now you have a recursive macro. This macro will keep executing until an
unsuccessful movement, for example f
is used to find a character, but the
character does not exist. Or, when j
is used to move the cursor down, but you
are at the end of the file.
You can use this technique instead of recording a macro and playing the macro X times. X isn’t always immediately obvious.
For greatest effectiveness start with an empty macro before creating a recursive macro.
-
qqq
empty the macro for the register q. -
qq
to start recording into register q. -
@q
to call the macro you are now recording. -
q
to stop recording. -
@q
to play the macro from register q.
Now you have a lot of qs.