3

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?

Adam
  • 161
  • 7

1 Answers1

5

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
…
romainl
  • 186,200
  • 21
  • 280
  • 313