I would like to apply macro a to a set of lines. For consecutive lines, this can be done by:5,10norm! @a(https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines).How to do it for every n-th line from my current cursor position?
Apply macro to every `n`-th line
macro
How about writing a 2nd macro that moves down n lines and then executes @a? Using a mark you can easily jump back to your original position.E.g., having defined your macro in register a, press qb to record in register b, press 5j to go to line 6, press @a to execute a and then q to quit recording. Using 9@b will then execute macro a on every 5th line, i.e. lines 11, 16, 21,..., up to line 51. Since j will fail at the end of the file, simpy use 1000@b for the whole file... adjust numbers as needed.