在一行中进行多次搜索和替换 [英] Multiple search and replace in one line

查看:25
本文介绍了在一行中进行多次搜索和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做:

<块引用>

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

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

解决方案

尝试

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

阅读

:help :s_flags

尤其是[e]下的条目:

 当搜索模式失败时,不要发出错误消息,并且在特别是,在地图中继续,就好像没有发生错误一样.这是最有助于防止不匹配"错误破坏映射.维姆但是,不会抑制以下错误消息:正则表达式不能用字母分隔\ 后面应该跟/, ?或 &没有以前的替代正则表达式尾随字符中断

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"?

解决方案

Try

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

and read

: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

这篇关于在一行中进行多次搜索和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆