在所有 VI 缓冲区中查找/Grep

发布于 2024-10-06 20:53:17 字数 222 浏览 6 评论 0原文

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

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

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

With many buffers open, I need a simple way to search all buffers for a regex and navigate the search result (quick list?)

I know I can :bufdo command, and it is easy to search and replace with %s, but I can't find a way to do just a simple search and then navigate the results.

I found plugins for that (e.g., buffergrep), but I'll be surprised if this simple task is not natively supported with a vim trick.. is it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(3

南七夏 2024-10-13 20:53:17

:grep & co. 将填充 QuickFix 缓冲区,从而允许在结果之间快速导航。

:grep & co. will populate the QuickFix buffer, which allows for fast navigation among results.

笨笨の傻瓜 2024-10-13 20:53:17

来自 :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"

from :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"
陪我终i 2024-10-13 20:53:17

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

据我所知没有。尝试提供此功能的多个插件的存在往往证实了这一点。 。 。

您尝试过哪些插件以及它们缺少什么?

http://www.vim.org/scripts/script.php?script_id=2545
http://www.vim.org/scripts/script.php?script_id=2255

另外,为了确保您知道 vimgrep,对吗? Vimgrep 是一个内部命令,它将文件加载到缓冲区中并在缓冲区上执行 grep,结果显示在快速修复窗口中。我还没有确认,但我假设如果搜索到的文件已经在缓冲区中打开,Vimgrep 不会重新加载它,至少在设置了“nomodified”标志的情况下不会。如果是这样,使用 Vimgrep 进行快速简单的缓冲区 grep 的一种方法是使用 :buffers 命令的输出为 Vimgrep 创建文件列表。

"I found plugins for that (e.g., buffergrep), but I'll be surprised if this simple task is not natively supported with a vim trick.. is it?"

Not that I know of. And existence of multiple plugins trying to offer this functionality tends to confirm that. . .

What plugins have you tried and what have they been lacking?

http://www.vim.org/scripts/script.php?script_id=2545
http://www.vim.org/scripts/script.php?script_id=2255

Also, just to make sure, you are aware of vimgrep, right? Vimgrep is an internal command that loads files into buffers and does greps on the buffers, with results in quickfix window. I haven't confirmed, but I assume if a searched file is already open in a buffer that Vimgrep doesn't reload it, at least not if it has 'nomodified' flag set. If so, one way to use Vimgrep for quick-and-easy buffer grepping would be to just create a file list for Vimgrep using the output from the :buffers command.

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