Comment by rav
5 days ago
To run a macro on the start of each line matching your search, you can use:
:g//norm @q
Here, g// repeats the most recent search, and norm @q runs the q macro on each matched line. This is not quite the same as starting the macro with a search, since the cursor is at the start of the line and not at the start of the match, but it's often good enough.
You can also restrict it to just the matches inside a range of lines: First select the lines in visual mode, then type :g//norm @q, which will cause Vim to insert a range before g, as in: :'<,'>g//norm @q, which means "between line '< and '>, find lines containing a match of the most recent search, and run @q on each such line".
Thanks!