Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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).

share|improve this answer
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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.