I saw an example of a recursive vim macro, and it stops, but I don't quite understand why. My guess is that it stops because it can't find any more :, but I'm unsure if I am correct; does anyone know why it stops?

Macro contents:


Register a is first empties with qaq and then recorded into with qa{...}q

2 Answers 2


From repeat.txt:

The register is executed like a mapping

and map.txt:

Note that when an error is encountered (that causes an error message or beep) the rest of the mapping is not executed.

So there's been some kind of error before reaching the @a. The documentation doesn't give an exhaustive list of all the possible errors for each action, but the most likely options are:

  • f didn't find a :
  • j couldn't move down (because there were no more lines in the buffer)

It depends what data you run it on. In the animated gif in the linked page, you're correct that it stops because the f command cannot find a colon.

If instead every line in the file from the cursor on downwards contained a colon, the macro would stop when the j command cannot move down, i.e. at the bottom of the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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