4

Is there a way to make a macro operate up to a marker? I know if I do 5@a my macro will operate on 5 lines. Example:

set marker with `mc`
record a macro with `qa`
... now what?

Obviously 'c@a just moves the cursor to the marker at c. I've tried buffers, "b'c, but that just goes to the marker. I'm probably missing something very basic or just looking in the wrong places.

Caleb
  • 69,278
  • 18
  • 196
  • 226
zje
  • 2,251
  • 14
  • 20

2 Answers2

3

You might try this:

:.,'c normal @a

This uses the “ranged” :normal command to run the normal-mode command @a with the cursor successively positioned on the first column of each line starting with current line and going down to to the line with mark c. If the mark happens to be above the cursor, then Vim will ask if you want to reverse the range.

This is not always the same as applying a count to @a (e.g. 5@a) because the content of register a may not always move down a single line each time it is executed (consider a “macro” that uses searches to move around instead of j or k: it would require a higher count to fully process lines that have multiple matches).

Chris Johnsen
  • 19,790
  • 8
  • 63
  • 52
  • This seems to have done the trick for what I was trying to do, thanks! (I was only using simple macros with predictable movement, so it works great!) – zje Aug 24 '11 at 17:26
0

One solution would be to setup your macro to assume and operate on the current selection, then select the part of the file you want to operate on before you run it.

Caleb
  • 69,278
  • 18
  • 196
  • 226