【问题标题】:Find/Grep in all VI buffers在所有 VI 缓冲区中查找/Grep
【发布时间】:2011-01-19 05:12:32
【问题描述】:

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

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

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

【问题讨论】:

标签: search vim macvim


【解决方案1】:

:grep & co. 将填充 QuickFix 缓冲区,以便在结果之间快速导航。

【讨论】:

  • 你能用它来 grep 缓冲区而不是文件
  • @Samer Abukhait:文档建议:call setqflist([]) | bufdo grepadd! something %,还有一些额外的工作来处理更多案件。
  • grepadd!似乎可以解决问题。文档不够清楚,我无法将其映射到所需的行为或回答诸如(语法元素是什么?和/或我可以使用“%”以外的其他东西吗?)。但在所有情况下,我现在都有办法做我想做的事,为此我感谢你!
  • 对于已经加载的缓冲区,vimgrep 代替grep 是更好的解决方案。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多