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:

i<Tab>'<Esc>f:C',<Esc>j^@a

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

up vote 2 down vote accepted

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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