Vim macros can also be recursive. This is useful for when you need to act on every line (or other text object) till the end of the file.
To record a recursive macro, start with an empty register. (A register can be emptied using q<register>q
.)
Choose a consistent starting point on each line to start and finish.
Before finishing recording, invoke the macro itself as the last command. (This is why the register must be empty: so it'll do nothing, as the macro doesn't exist yet).
Example, given the text:
line 1
line 2
line 3
foo bar
more random text
.
.
.
line ???
In normal mode, with the cursor on the first line and a empty register a
, one could record this macro:
qaI"<Esc>A"<Esc>j@aq
Then with a single invocation of @a
, all the lines of the file would be now inside double quotes.