【发布时间】:2011-01-19 05:12:32
【问题描述】:
由于打开了许多缓冲区,我需要一种简单的方法来搜索所有缓冲区以查找正则表达式并导航搜索结果(快速列表?)
我知道我可以使用:bufdo 命令,并且很容易用%s 进行搜索和替换,但我找不到一种方法来进行简单的搜索然后浏览结果。
我找到了插件(例如,buffergrep),但如果这个简单的任务不支持 vim 技巧,我会感到惊讶.. 是吗?
【问题讨论】:
由于打开了许多缓冲区,我需要一种简单的方法来搜索所有缓冲区以查找正则表达式并导航搜索结果(快速列表?)
我知道我可以使用:bufdo 命令,并且很容易用%s 进行搜索和替换,但我找不到一种方法来进行简单的搜索然后浏览结果。
我找到了插件(例如,buffergrep),但如果这个简单的任务不支持 vim 技巧,我会感到惊讶.. 是吗?
【问题讨论】:
:grep & co. 将填充 QuickFix 缓冲区,以便在结果之间快速导航。
【讨论】:
:call setqflist([]) | bufdo grepadd! something %,还有一些额外的工作来处理更多案件。
vimgrep 代替grep 是更好的解决方案。
来自:help grepadd
:grepa[dd][!] [arguments]
Just like ":grep", but instead of making a new list of
errors the matches are appended to the current list.
Example:
:call setqflist([])
:bufdo grepadd! something %
The first command makes a new error list which is
empty. The second command executes "grepadd" for each
listed buffer. Note the use of ! to avoid that
":grepadd" jumps to the first error, which is not
allowed with |:bufdo|.
An example that uses the argument list and avoids
errors for files without matches:
:silent argdo try
\ | grepadd! something %
\ | catch /E480:/
\ | endtry"
【讨论】:
“我找到了插件(例如,buffergrep),但如果这个简单的任务不支持 vim 技巧,我会感到惊讶.. 是吗?”
我不知道。并且尝试提供此功能的多个插件的存在往往证实了这一点。 . .
您尝试过哪些插件,它们缺少什么?
http://www.vim.org/scripts/script.php?script_id=2545
http://www.vim.org/scripts/script.php?script_id=2255
另外,为了确保您了解 vimgrep,对吗? Vimgrep 是一个内部命令,它将文件加载到缓冲区并在缓冲区上执行 greps,结果显示在 quickfix 窗口中。我还没有确认,但我假设如果搜索到的文件已经在缓冲区中打开,Vimgrep 不会重新加载它,至少在它设置了“nomodified”标志的情况下不会。如果是这样,使用 Vimgrep 进行快速简单的缓冲区 grepping 的一种方法是使用 :buffers 命令的输出为 Vimgrep 创建一个文件列表。
【讨论】: