VIM:使用增量搜索进行文件替换

发布于 2024-12-09 19:02:15 字数 113 浏览 0 评论 0原文

我知道 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女七分熟 2024-12-16 19:02:15

最简单的方法是像平常一样进行搜索,使用 'incsearch' 来帮助确保模式与您想要的匹配。一旦确定了这一点,您就可以

  • 忽略 :%s//bar/ 中的搜索模式。当没有指定的搜索模式时,将使用 / 寄存器的当前值,这将是您刚刚执行的搜索。
  • 使用 Ctrl+r/ 将搜索模式插入到 :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

  • Leave out the search pattern in :%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.
  • Insert the search pattern into the :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.
宛菡 2024-12-16 19:02:15

您可以在命令末尾添加 c ,如下所示:

:%s/foo/bar/c

它将遍历 foo 的所有实例并要求您确认(这就是 c< /code> 代表),然后将其更改为 bar

但这并不完全是你所追求的。

You could add c at the end of your command like that:

:%s/foo/bar/c

It will walk through all the instances of foo and ask for your confirmation (that's what the c stands for) before changing it to bar.

It's not exactly what you are after though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文