Vim 中的交互式搜索/替换正则表达式? [英] Interactive search/replace regex in Vim?

查看:46
本文介绍了Vim 中的交互式搜索/替换正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道进行全局替换的正则表达式,

I know the regex for doing a global replace,

     %s/old/new/g

您如何在 Vim 中进行交互式搜索替换?

How do you go about doing an interactive search-replace in Vim?

推荐答案

添加标志 c(在 vim 命令提示符下):

Add the flag c (in the vim command prompt):

:%s/old/new/gc

每次出现旧"时都会给您是/否提示.

will give you a yes/no prompt at each occurrence of 'old'.

Vim 的内置帮助提供了有关选择确认替换后可用选项的有用信息.使用:

Vim's built-in help offers useful info on the options available once substitution with confirmation has been selected. Use:

:h :s

然后滚动到确认选项部分.截图如下:

Then scroll to section on confirm options. Screenshot below:

例如,要替换此匹配项和所有剩余匹配项,请使用 a.

For instance, to substitute this and all remaining matches, use a.

这篇关于Vim 中的交互式搜索/替换正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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