« Back to Index

Vim Grep

View original Gist on GitHub

Vim Grep.md

Standard Vim Grep

Basic syntax structure:

:vimgrep  /<searchTerm>/[gj] </path/to/project/**/*.rb>
:lvimgrep /<searchTerm>/[gj] </path/to/project/*>

Note: j prevents Vim from trying to open the first file match

Example usage (we’re searching for any reference to class anywhere in the project):

:vimgrep /class/gj **/*
:copen

Note: copen will open Vim’s “quick fix” window

Using an alternative search tool

Vim provides a :grep command, which allows you to utilise a custom search program.

The default program it uses can be seen by running:

:set grepprg

Which should return:

grepprg=grep -n $* /dev/null

Configuring Vim to use another program (e.g. Sift)

:set grepprg=sift\ -n\ -X\ log\ --binary-skip\ $*

Note: spaces have to be escaped with a backslash \

You can now use the new program like so (e.g. to find any reference to the word class using Sift):

:grep class
:copen

Note: you still need to open the quick fix window afterwards to utilise the results