Greplace 的语法
我想使用 VIM 更改几个文件中的一些单词。为此,我发现了 Greplace,它似乎是就是这样做。但是,在 文档 中没有示例Greplace 的语法(有 Gsearch 的示例,但我需要替换功能)。
假设我想在所有“.asp”文件中将“foo”更改为“bar”,如何使用 Greplace (或任何其他方法)来实现这一点。我不关心确认(需要确认也可以,不需要确认也可以)。
I want to change some words in several files using VIM. To do this, I found out about Greplace, which appears to be made to do just that. However, in the documentation there is no sample of the syntax of Greplace (there is a sample of Gsearch, but I need the replace function).
Say I want to change "foo" for "bar" in all ".asp" files, how could that be achieved with Greplace (or any other method). I do not care about confirmation (it's fine if it requires confirmation; it's also fine if it does not).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有专门的插件,这件事就很简单了。
:bufdo
在所有缓冲区上运行以下命令。%s/foo/bar/ge
将所有行以及每行中所有出现的 foo 替换为 bar。e
标志确保:s
在找不到 foo 时不会发出错误,因为 foo 可能并不存在于所有文件中。|
是 Vim 分隔多个命令运行的方式。请参阅:help :bar
update
仅当实际进行了任何更改时才会将文件保存回磁盘。It's trivial to do without a dedicated plugin.
:bufdo
runs the following commands on all buffers.%s/foo/bar/ge
replaces foo with bar on all lines and all occurrences in each line. Thee
flag makes sure:s
doesn't emit an error if it doesn't find foo, since foo may not exist in all the files.|
is Vim's way of separating multiple commands to run. See:help :bar
update
saves the file back to disk, only if any changes were actually made.