开发者

Find/Grep in all VI buffers

开发者 https://www.devze.com 2023-01-29 19:09 出处:网络
With many buffers open, I need开发者_如何转开发 a simple way to search all buffers for a regex and navigate the search result (quick list?)

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?


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


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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号