多行搜索并替换一行

时间:2011-01-19 15:28:35

标签: vim

如果我这样做:

  

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

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

1 个答案:

答案 0 :(得分:89)

尝试

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

并阅读

: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.  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