多行搜索并替换一行

rtu*_*ado 58 vim

如果我这样做:

:%s/aaa/bbb/| %S /二百二十二分之一百十一/

并且第一次搜索和替换没有找到任何匹配,第二次搜索和替换将不会被执行.即使命令"失败",有没有办法告诉vim继续?

Ren*_*ger 91

尝试

:%s/aaa/bbb/e | %s/111/222/e
Run Code Online (Sandbox Code Playgroud)

并阅读

:help :s_flags
Run Code Online (Sandbox Code Playgroud)

特别是[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
Run Code Online (Sandbox Code Playgroud)

  • 注意为每个`s`添加一个'%`.当我尝试这个时,我不小心只在第一个替换前放了一个`%`.该命令仍然可以正常运行,但它不会执行您希望它执行的替换. (3认同)