10

随着许多缓冲区打开,我需要一种简单的方法来搜索所有缓冲区的正则表达式并导航搜索结果(快速列表?)

我知道我可以:bufdo命令,并且很容易搜索和替换为%s,但我找不到一种方法来进行简单的搜索然后导航结果。

我找到了插件(例如,buffergrep),但如果这个简单的任务不支持vim技巧,我会感到惊讶..是吗?

4

3 回答 3

4

:grep公司 将填充 QuickFix 缓冲区,允许在结果之间快速导航。

于 2010-12-08T20:05:58.820 回答
4

: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"
于 2011-01-18T21:12:32.603 回答
2

“我找到了插件(例如,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 创建一个文件列表。

于 2010-12-08T22:33:16.570 回答