4

The contents of register w are xx. When I try to run the following command:

:for i in range(1,10) | if i > 5 | @w | endif | endfor

It throws an error saying that E492: Not an editor command xx.
How do I execute the macro?

1 Answer 1

7

Use :h execute combined with :h normal, like so:

:for i in range(1,10) | if i > 5 | exe "normal @w" | endif | endfor

Short explanation: execute/exe runs it's argument as an Ex command and normal behaves as you would press given symbols/keys yourself.

2
  • 1
    Or in this case, just normal @w. Or normal! @w, in case you have @ mapped.
    – tbodt
    Feb 15, 2017 at 17:25
  • For some reason normal @w didn't worked for me, but I didn't want to focus on that if using exe did the trick
    – grodzik
    Feb 16, 2017 at 7:52

Your Answer

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

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