2010-12-08 91 views
10

隨着多個緩衝區開放,我需要一個簡單的方法來搜索所有緩衝區爲正則表達式和瀏覽搜索結果(快速列表?)查找/ grep的所有VI緩衝區

我知道我可以:bufdo命令,它很容易搜索和替換%s,但我找不到一個方法來做一個簡單的搜索,然後導航結果。

我找到了那個插件(例如buffergrep),但是如果這個簡單的任務本身不支持vim技巧,我會感到驚訝。是嗎?

+0

的可能的複製[如何搜索Vim中打開的緩衝區?(http://stackoverflow.com/questions/11975174/how-do-i-search-the- open-buffers-in-vim) – 2016-05-17 07:03:01

回答

4

:grep & co.將填充QuickFix緩衝區,該緩衝區允許在結果中快速導航。

+2

你可以使用它來在BUFFERS而不是文件中grep – 2010-12-08 20:09:14

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是一個內部命令,它將文件加載到緩衝區中,並對緩衝區執行grep操作,並在quickfix窗口中生成結果。我還沒有確認,但是我假設搜索到的文件已經在Vimgrep沒有重新加載的緩衝區中打開,至少如果已經設置了「nomodified」標誌的話。如果是這樣,使用Vimgrep進行快速簡單緩衝區刷新的一種方法是使用:buffers命令的輸出創建Vimgrep的文件列表。

3
: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"