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?

TheChetan
  • 417
  • 4
  • 11

1 Answers1

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.

grodzik
  • 4,588
  • 19
  • 27
  • 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 07:52