I have an error-checking one-liner vim command that looks like the following. It's not directly part of the question but works as an example, so feel free to ignore it:
:'<,'>g/foo{.*}/exe "norm! mxf{lvt}y/\\(foo{\\)\\@!\<C-R>\"\<enter>yy'xP"
Here is an explanation:
:'<,'>g/foo{.*}/
- Run the following command on all highlighted lines withfoo{...}
exe "norm!
- Start executing normal mode commands on each linemx
- Record the current linef{lvt}y
- Copy everything inside the curly braces offoo{...}
/\\(foo{\\)\\@!\<C-R>\"\<enter>
- Forward search to an instance where the string inside the curly braces offoo{...}
is not insidefoo
yy'xP"
- Copy that line, go back tox
, and paste it above.
This is basically an error-checking command to see that every time a term is wrapped by foo{
, it is always wrapped by foo. However, exe
exits on the first case where /
(forward search) doesn't find anything. I don't want that to happen.
How do I make exe
and :g
continue even with errors inside the exe
command? I have tried :silent
, but that does not save it.
I'd rather keep this as a one-liner, but functions are a second option I am okay with.