VIM:使用增量搜索进行文件替换
我知道 incsearch
设置控制在您键入时 vim 中的搜索如何突出显示。我希望在使用替换命令时进行相同的增量搜索和突出显示 (:%s/foo/bar/
)
I know that the incsearch
setting controls how search in vim highlights as you type. I would like to have the same incremental search and highlight when using the replace command (:%s/foo/bar/
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是像平常一样进行搜索,使用
'incsearch'
来帮助确保模式与您想要的匹配。一旦确定了这一点,您就可以:%s//bar/
中的搜索模式。当没有指定的搜索模式时,将使用/
寄存器的当前值,这将是您刚刚执行的搜索。:s
命令中(请参阅:help c_ctrl -r
) 或Ctrl+rCtrl+o/(如果搜索包含控制字符,就像^H
)。如果您想对模式进行一些最终调整,或者希望将其保留在命令历史记录中,以便即使在执行另一次搜索后也可以重用它,这非常有用。The easiest way to do that is to do a search like normal, using
'incsearch'
to help ensure the pattern is matching what you want. Once you've got that nailed down, you can either:%s//bar/
. When there's no specified search pattern, the current value of the/
register is used, which will be the search you just did.:s
command using Ctrl+r/ (see:help c_ctrl-r
) or Ctrl+rCtrl+o/ (if the search contains control characters, like^H
). This is useful if you want to make some final tweaks to the pattern or if you want to have it in your command history so you can reuse it even after performing another search.您可以在命令末尾添加
c
,如下所示:它将遍历
foo
的所有实例并要求您确认(这就是c< /code> 代表),然后将其更改为
bar
。但这并不完全是你所追求的。
You could add
c
at the end of your command like that:It will walk through all the instances of
foo
and ask for your confirmation (that's what thec
stands for) before changing it tobar
.It's not exactly what you are after though.