Comment by rav
6 days ago
There's also the no-macro solution where you just use ":%norm [series of keystrokes]" to run the given keystrokes on each line, but that comes with the added difficulty of not giving any visual feedback of what the keystrokes will do before you submit the entire line.
One thing to keep in mind is that ":%norm" will place the cursor at the start of each line, before any indentation, whereas the trick of ending the macro with "+" will place the cursor at the start of each line after the indentation. But this can be worked around with ":%norm ^@q", using ^ to skip indentation before running macro q on each line.
Related to that, macros are just recorded into normal registers. You can get it out with:
Edit it, and put it back into the register with
Heads up - you should use "qD instead of "qdd to avoid an extra newline at the end of the register contents. (In fact the current Vim 9.1.954 behavior seems a bit odd in that it moves the cursor down, but not to the start of the line, as if j is pressed... Seems like a bug to me.)
And D goes from cursor to end of line instead of the whole line. Wasn't sure how complicated I wanted the description to be.