sponsor Vim development Vim logo Vim Book Ad

EasyGrep : Fast and Easy Find and Replace Across Multiple Files

 script karma  Rating 344/110, Downloaded by 9425  Comments, bugs, improvements  Vim wiki

created by
Daniel Price
script type
EasyGrep is a plugin for performing search and replace operations through multiple files. Vim already has builtin support for searching through files with its 'vimgrep' and 'grep' commands, but EasyGrep makes using them much, much easier. It also provides a powerful "Replace in Files" operation, something that is not very easy to do in Vim by default. With EasyGrep, you can specify with high-precision exactly the type of files you want to search, whether it be all files, only open buffers, only files matching a pattern, etc. Additionally, you can easily specify searching through hidden files, case-sensitivity, performing a recursive search, and many more options that make searching more easy.

EasyGrep provides both key mappings and commands to make search and replace easy. When using EasyGrep, searching for a word is as easy as typing <leader>vv (v v, not double-u) over the word for which you want to search.  This search can also be accomplished with the :Grep command and a user-specified pattern. Performing a "replace in files" is similar; type <leader>vr or use the :Replace command. Setting options is easy, simply type <leader>vo or :GrepOptions.  EasyGrep provides a great set of defaults but can also be configured to start up just how you like it; see the script for these options.  Most vimgrep (and grepprg) options are supported.  

For an in-development version of EasyGrep go to http://github.com/dkprice/vim-easygrep


    <Leader>vv  - Grep for the word under the cursor, match all occurences,
                  like |gstar|
    <Leader>vV  - Grep for the word under the cursor, match whole word, like
    <Leader>va  - Like vv, but add to existing list
    <Leader>vA  - Like vV, but add to existing list
    <Leader>vr  - Perform a global search search on the word under the cursor
                  and prompt for a pattern with which to replace it.
    <Leader>vo  - Select the files to search in and set grep options


    :Grep [arg]
        Search for the specified arg, like <Leader>vv.  When an ! is added,
        search like <Leader>vV

    :GrepAdd [arg]
        Search for the specified arg, add to existing file list, as in
        <Leader>va.  When an ! is added, search like <Leader>vA

    :Replace [target] [replacement]
        Perform a global search and replace.  The function searches
        the same set of files a grep for the desired target and opens a dialog to
        confirm replacement.
        Undoes the last :Replace operation.  Does not stack successive
        searches; only the last replace may be undone.  This function may not
        work well when edits are made between a call to Replace and a call to

    :GrepOptions [arg]
        Open a window to set grep options.
install details
Copy EasyGrep.vim and EasyGrepFileAssociations to your plugin directory; copy EasyGrep.txt to your doc directory.  Run helptags on your doc directory.

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
EasyGrep.zip 1.1 2013-02-17 7.0 Daniel Price Improved: much better support when grepprg is ack or grep. These tools can search much more quickly than vimgrep and so may be preferable to some users.
Feature: added a mapping to echo the command that EasyGrep will issue (see 'v' in the options explorer)
Feature: Added keymap toggle for EasyGrepSearchCurrentBufferDir
Fixed: command line parsing of Grep command discarded spaces
Feature: added support for grep exclusions when grepprg is grep or ack
Feature: Added EasyGrepDefaultUserPattern option.  Thanks to Jesus Barcons for the suggestion.
Improved: Cleaned up the documentation
Improved: Cleaned up the internals of the script substantially
Improved: Formalized multi-select mode, which is when multiple file extensions are selected from the options explorer
Improved: lots of misc fixes
EasyGrep.zip 1.0 2011-10-21 7.0 Daniel Price Documentation: Added a help tag for each of the commands so that you can
    look up more information on them.
Improved: Cleaned up the internals of the script substantially
Improved: Changed the name of FilterErrorList to ResultListFilter
Feature: Added ResultListOpen command to open all of the files in the
    result list (aka error list)
Fixed: Added -- to signify the end of the command line options. Grepping
    for patterns such as '->var' are now possible with ':Grep -- ->var'
EasyGrep.zip 0.98 2010-11-06 7.0 Daniel Price Highlight: The Replace and ReplaceUndo commands were reimplemented.  The granularity of matches inside of a Replace call were improved so that you can now decide replacements individually per line.
    Additionally, Complex operations such as replacing x[i][j][k] with x(i,j,k) and following it up with a ReplaceUndo are now possible.

    :Replace /x\[\([^]]\+\)\]\[\([^]]\+\)\]\[\([^]]\+\)\]/x(\1,\2,\3)/

    Please report any regressions with either of these functions.

Feature: Added count command line option (-m 4 or -4)
Feature: Improved Grep options window keybindings; searching within the options explorer window is now possible
Feature: Expanded searches to include all of the active buffers' directories
Bugfix:  Fixed recursive operation and expanded search from reporting duplicate results
Bugfix:  Fixed <C-e> and <C-y> in replace mode
Feature: Added EasyGrepWindowPosition for specifying where the error list window will be opened
Feature: Added FilterErrorlist command for filtering the results within the quickfix or location list windows
Feature: Improved printout when no matches are found
Feature: Improved searching when an entire line is selected
EasyGrep.zip .96 2009-11-13 7.0 Daniel Price Feature: Expanded upon the list of file associations
Feature: Expanded searches to the current buffer's directory in addition to the current working directory
Feature: Added command line arguments to :Grep and :Replace for recursive searches and case sensitivity
Feature: Added toggle for window replace mode
Feature: Added toggle for showing file associations list in options explorer
Bugfix: Case insensitivity would fail in replacing some patterns
EasyGrep.zip 0.951 2009-03-23 7.0 Daniel Price Update to 0.95: Fixed an error in calling ReplaceCurrentWord identified by Eric Ho.

Feature: Added search and replace on visual selections.
Feature: Improved Grepping for items that can be interpreted as regular expressions.  Selections are assumed to be literal, whereas explicit commands are assumed to be regular expressions.
Feature: Removed option g:EasyGrepNoDirectMappings in favor of g:EasyGrepOptionPrefix, which allows the option prefix to be changed.
Bugfix:  The tracked extension would sometimes fail to be updated when switching between buffers
Documentation: Split the documentation into its own file; greatly expanded upon its contents.
Change: Activating a mode that is already activated will no longer deactivate it.
Change: GrepOptions no longer accepts an argument; use user mode instead.
Change: Clarified mapping names; custom mappings will need to be reset.
EasyGrep.zip 0.9 2009-01-27 7.0 Daniel Price Feature: Added forward slash delineated pattern to the Replace command
e.g. :Replace /target/replacement/
that allows more complicated replacements; you can now work with
patterns that have spaces in them.
Bugfix: If cursorline is off at the start of a replace, now ensuring that cursorline is turned off for all buffers, and not just the last one
Bugfix: fixed an issue with an extra tab being opened during a replacement
EasyGrep.zip 0.8 2009-01-11 7.0 Daniel Price Implemented case sensitivity that is independent of ignorecase; thanks to Doro Wu for contributing to this functionality
Changed shortcut key for hidden files from 'i' to 'h'
EasyGrep.zip 0.7 2008-12-26 7.0 Daniel Price Expanded search of EasyGrepFileAssociations list to every component of 'runtimepath'.  This solves a starting message for those who placed EasyGrepFileAssociations in a location other than the first location in 'runtimepath'.
EasyGrep.zip 0.6 2008-12-09 7.0 Daniel Price Fixed paths with spaces in them
Folds will now be disabled where replacements are to be made
Fixed an error with checking for extra warnings
Better highlighting while replacing
Recursive mode can no longer be activated when Buffers mode is activated
EasyGrep.zip 0.5 2008-11-24 7.0 Daniel Price Fixed an issue with tracking the file extension where sometimes the desired extension wouldn't be registered.
Better reporting when no files match.
Now warning when searching from a working directory that doesn't match the current file's directory.
Added g:EasyGrepExtraWarnings option.
EasyGrep.zip 0.4 2008-11-21 7.0 Daniel Price Improved Replace and ReplaceUndo
Added two configurable modes for how the windows operate when doing a global replace.
Fixed an issue with linked filetypes.
EasyGrep.zip 0.3 2008-11-19 7.0 Daniel Price Added experimental :Replace and :ReplaceUndo commands; keymapped <leader>vr for :Replace
Improved response when no matches
EasyGrep.zip 0.2 2008-11-15 7.0 Daniel Price Added option to toggle showing fewer or more options; showing fewer options by default.
Added option '?' to print the current configuration and save it to a register.
Now creating direct mapping by default; see g:EasyGrepNoDirectMappings to turn this off.
EasyGrep.zip 0.1 2008-11-13 7.0 Daniel Price Initial upload
ip used for rating:

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