在一行中进行多次搜索和替换

如果我这样做:

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

如果第一次搜索和替换没有找到任何匹配,则不执行第二次搜索和替换。有没有办法告诉 Vim 即使命令“失败”也要继续?

33308 次浏览

试试看

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

读书

: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