在 Vim 中搜索和替换所有项目文件 [英] Search and replace in Vim across all the project files

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

问题描述

我正在寻找在 Vim 中的所有项目文件中进行搜索和替换(需确认)的最佳方法.项目文件"是指当前目录中的文件,其中一些文件不必打开.

I'm looking for the best way to do search-and-replace (with confirmation) across all project files in Vim. By "project files" I mean files in the current directory, some of which do not have to be open.

一种方法是简单地打开当前目录中的所有文件:

One way to do this could be to simply open all of the files in the current directory:

:args ./**

然后对所有打开的文件进行搜索和替换:

and then do the search and replace on all open files:

:argdo %s/Search/Replace/gce

但是,当我这样做时,Vim 的内存使用量从几十 MB 跃升至 2 GB 以上,这对我不起作用.

However, when I do this, Vim's memory usage jumps from a couple dozen of MB to over 2 GB, which doesn't work for me.

我也安装了 EasyGrep 插件,但它几乎从来没有工作过——要么没有没有找到所有的出现,或者它只是挂起,直到我按下 CtrlC.到目前为止,我完成此任务的首选方法是 ack-grep 用于搜索词,使用它的快速修复窗口打开任何包含该术语且之前未打开的文件,最后 :bufdo %s/Search/Replace/gce.

I also have the EasyGrep plugin installed, but it almost never works—either it doesn't find all the occurrences, or it just hangs until I press CtrlC. So far my preferred way to accomplish this task it to ack-grep for the search term, using it's quickfix window open any file that contains the term and was not opened before, and finally :bufdo %s/Search/Replace/gce.

我正在寻找可用于此目的的良好、有效的插件,或者比我现在使用的更容易的命令/命令序列.

I'm looking either for a good, working plugin that can be used for this, or alternatively a command/sequence of commands that would be easier than the one I'm using now.

推荐答案

Greplace 对我来说效果很好.

github 上还有一个病原体就绪版本.

There's also a pathogen ready version on github.

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

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