Reputation: 19
I'm trying to write my first macro and it's giving me some trouble
I basically want to turn this:
cityName1
cityName2
etc...
into this:
'cityName1',
'cityName2',
etc...
I recorded the macro as: i'<Esc>A'<Esc>j0
, and if I execute as @a
it works fine, but when I try something like :10@a
it gives me a 'E488 Trailing Characters Error'
Any help would be appreciated, thanks
Upvotes: 1
Views: 128
Reputation: 196516
A macro is a sequence of keystrokes that are meant to be repeated literally by Vim.
When you do @a
in normal mode, Vim does i
, then '
, then <Esc>
, etc. for you and it all works as expected because you are in normal mode and your macro starts with a normal mode command.
When you do @a
in command-line mode, Vim does the same thing as above (i
, then '
, etc.) but you are in command-line mode and those keystrokes are meaningless in that context. You are basically inputting garbage, Vim is trying its best to make sense of it, and it is failing.
Note that the 10
in 10@a
means "replay @a
10 times" and the 10
in :10@a
means "replay @a
on line 10". Whether you want one or the other is not immediately obvious from your question.
In normal mode, do this if you mean "replay @a
10 times":
10@a
or that, if you mean "replay @a
on line 10":
1OG@a
If you prefer command-line mode, do this if you mean "replay @a
10 times":
:normal 10@a
or that, if you mean "replay @a
on line 10":
:1Onormal @a
See :help G
, :help :normal
, :help :range
, and more generally, :help repeat
.
Upvotes: 1