Part of a macro I'm writing deletes any blank lines, and then does some more work (joining the expected two remaining lines and then appending to them). Simplified version:
let @m=':g/^$/d^MggJA ^['
(Where of course ^M and ^[ are the CR and ESC literals.)
However, sometimes my input doesn't include any blank lines, and I can't get the macro to proceed when the :g
command fails:
Pattern not found: ^$
(Same happens with different message when I try :v/./d
instead: Pattern found in every line: .
)
I got my hopes up when I found How to force macro keep running even pattern is not found?, where the answers suggest using :try
, but this doesn't seem to work with :g
or :v
:
:let @m=':try|:g/^$/d|catch||endtry^MggJA ^['
If this is run on input with no blank lines, it leaves the editor in command-line mode and I have to type endtry
to get out of it. I try adding an additional endtry
to the macro:
:let @m=':try|:g/^$/d|catch||endtry^Mendtry^MggJA ^['
This works for input with no blank lines. But when I go back and try this on input that contains blank lines, I get
E603: :catch without :try
Is there any hope to be had here?