Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search the open buffers in Vim?

Tags:

vim

search

I'd like to search for text in all files currently open in vim and display all results in a single place. There are two problems, I guess:

  • I can't pass the list of open files to :grep/:vim, especially the names of files that aren't on the disk;
  • The result of :grep -C 1 text doesn't look good in the quickfix window.

Here is a nice example of multiple file search in Sublime Text 2:enter image description here

Any ideas?

like image 534
squirrel Avatar asked Aug 15 '12 18:08

squirrel


People also ask

How do I navigate between buffers in Vim?

Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.

How do I close all buffers in Vim?

Just put it to your . vim/plugin directory and then use :BufOnly command to close all buffers but the active one.

How do I close all open files in Vim?

You can quit from all open files (buffers) by :qa or :qa! In vim. The exclamation mark means to force quit the edited unsaved file.

How does vi editor use buffers?

Whenever you delete something from a file, vi keeps a copy in a temporary file called the general buffer. You can also delete or copy lines into temporary files called named buffers that will let you reuse those lines during your current vi work session.


2 Answers

Or

:bufdo vimgrepadd threading % | copen 

The quickfix window may not look good for you but it's a hell of a lot more functional than ST2's "results panel" if only because you can keep it open and visible while jumping to locations and interact with it if it's not there.

like image 173
romainl Avatar answered Oct 13 '22 11:10

romainl


ack and Ack.vim handle this problem beautifully. You can also use :help :vimgrep. For example:

:bufdo AckAdd -n threading 

will create a nice quickfix window that lets you hop to the cursor position.

like image 21
Conner Avatar answered Oct 13 '22 10:10

Conner