If I have a regex
in a recorded macro and then run it over a line that the regex
fails to match the macro stops. For example, I have a list of files.
family-reunion-2015.webm
road-festival-20150607.webm
ireland.webm
bike-festival-201407.webm
bike-festival-201409.webm
Which I want to convert to:
<a href="family-reunion-2015.webm">
family reunion 2015</a>
<a href="road-festival-20150607.webm">
road festival 20150607</a>
<a href="ireland.webm">
ireland</a>
<a href="bike-festival-201407.webm">
bike festival 201407</a>
<a href="bike-festival-201409.webm">
bike festival 201409</a>
I record the following macro
inside the q register:
yyp:s/\-/ /g<ENTER>A<Esc>xxxxxi</a><Esc>kI<a href="<Esc>A"><Esc>JJ0
q
I start from the first character of the first line and finish at the first character of the next line, i.e. at the end of the macro i move to the beginning of the next line (JJ0
).
Then, I repeat the macro by typing 4@q. But i end with the following:
<a href="family-reunion-2015.webm">
family reunion 2015</a>
<a href="road-festival-20150607.webm">
road festival 20150607</a>
ireland.webm
ireland.webm
bike-festival-201407.webm
bike-festival-201409.webm
And an error message:
E486: Pattern not found: \-
Which is correct, but it stops the macro from advancing.
How can i tell vim to ignore this error and continue the macro processing?
I'm getting around this by doing :%s/webm$/we-bm/
and adding an extra x
to my macro. But there should be a more elegant way.