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?


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.

  • 1
    Or in this case, just normal @w. Or normal! @w, in case you have @ mapped.
    – tbodt
    Feb 15 '17 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 '17 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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