Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim replace after failed replace in macro

I have a big sequence of find and replace's in a macro

:let@m=':%s/√/\\sqrt/g
:%s/∫/\\int/g
:%s/∑/\\sum/g
:%s/∏/\\prod/g
:%s/⋃/\\bigcup/g
:%s/⋂/\\bigcap/g
:%s/∪/\\cup/g
:%s/∩/\\cap/g
:%s/∂/\\partial/g
:%s/–/\--/g
:%s/—/\---/g
:%s/•/\\bullet/g
:%s/·/\\cdot/g
:%s/◦/\\circ/g
:%s/±/\\pm/g
:%s/∓/\\mp/g
<more stuff/>
'

If any one of these find and replace's fails (for instance if there is no ∫ in the file), the subsequent ones don't get run. How can I make :%s///g fail quietly and nondestructively?

like image 241
Adam Avatar asked Apr 27 '26 15:04

Adam


1 Answers

From :help :s_flags:

[e]    When the search pattern fails, do not issue an error message and, in
       particular, continue in maps as if no error occurred.  This is most
       useful to prevent the "No match" error from breaking a mapping.

so:

%s/√/\\sqrt/ge
%s/∫/\\int/ge
…
like image 79
romainl Avatar answered Apr 29 '26 10:04

romainl