sponsor Vim development Vim logo Vim Book Ad

VimgrepBuffer : Run vimgrep on buffers

 script karma  Rating 10/4, Downloaded by 1202  Comments, bugs, improvements  Vim wiki

created by
Jeet Sukumaran
 
script type
utility
 
description
************************************************************************************
This plugin has been superceded by Buffersaurus, available at:
http://www.vim.org/scripts/script.php?script_id=3620
************************************************************************************

This plugin provides easy application of the 'vimgrep' command on buffers
(as opposed to the filesystem, which is its normal mode of operation).
It provides two commands: one to search just the current buffer, and the
other to search all listed buffers.
The QuickFix buffer will be populated with the search results, if any, and
opened for viewing. The search pattern will also be assigned to the search
register, so that matches will be highlighted if 'hlsearch' is on (':set
hlsearch').

Two commands are provided, ':G' and ':GG'. The first limits the search to
the current buffer, while the second searches all listed buffers.

If you do not like the cryptic/genericness of these 'short' commands, put:

    let g:vimgrepbuffer_long_command = 1

in your "~/.vimrc", and ':VimgrepBuffer' and ':VimgrepBuffers' will be set as
the commands instead.

The pattern specification is *exactly* like that for 'vimgrep'.  This means
that if the pattern starts with a non-identifier character or contains any literal whitespace
characters, for correct behavior you will have to enclose the pattern in
delimiter characters (e.g. "/", "@", "#"):

   :G /\s*print "\d/
   :GG /\s*def\s\+\w\+(/
   :G /\(def\s\+\|class\s\+\)/
   :GG /\cisland/
   :G /the quick brown \w\+/
   :GG /except \+\w\+Error/

If your pattern starts with an identifier-character you can omit the enclosing
delimiters:

   :G def\s\+\w\+(.*\*\*kwargs)
   :GG except\s\+\w\+Error

In this latter case, the pattern will be considered to be
whitespace-delimited, and so if your pattern contains any literal whitespace
you may get incorrect results. This behavior is exactly like that of
'vimgrep'.

You might also be interested in looking at "grep.vim" (http://www.vim.org/scripts/script.php?script_id=311) as an alternative for "grep-on-buffer" operations, especially if you want to use external grep programs.
"grep.vim" provides a much broader range of functionality and commands, and is typically faster.  However, the grep dialect you will have to use is that of the external grep programs, rather than that of Vim. The main reason I wrote "VimgrepBuffer" (and why you might be interested in using it) is to be able to use Vim's grep dialect to express the search patterns.
 
install details
You can use this script as a plugin by copying it to your plugin directory (e.g., "~/.vim/plugin")
See |add-global-plugin| for instructions.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vimgrepbuffer.vim 1.0.1 2010-09-09 7.0 Jeet Sukumaran Added examples and clarification of reg-exp behavior to script documentation comments.
vimgrepbuffer.vim 1.0 2010-09-09 7.0 Jeet Sukumaran Initial upload
ip used for rating: 3.144.109.5

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github