Multiple search and replace in one line

Vim

Vim Problem Overview


If I do something like:

> :%s/aaa/bbb/ | %s/111/222/

and the first search and replace doesn't find any matches, the second search and replace won't be executed. Is there any way to tell vim to carry on even when a command "failed"?

Vim Solutions


Solution 1 - Vim

Try

:%s/aaa/bbb/e | %s/111/222/e

and read

https://vimhelp.appspot.com/change.txt.html#%3As_flags">:help :s_flags

especially the entry under [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.  Vim
 does not suppress the following error messages, however:
 Regular expressions can't be delimited by letters
 \ should be followed by /, ? or &
 No previous substitute regular expression
 Trailing characters
 Interrupted

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrturradoView Question on Stackoverflow
Solution 1 - VimRené NyffeneggerView Answer on Stackoverflow