Skip to content

A utility for grepping that isn't limited to a specific program

Notifications You must be signed in to change notification settings

chrisjohnson/vim-grep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

Grep

A utility for grepping that isn't limited to a specific program

Selection

  • grep.vim will try to use rg if available.
  • If rg is unavailable, and the file is in a git repo, git-grep will be used.
  • If not, it will fallback to ag.
  • If ag is unavailable, grep will be used.

Note This will clobber your g:grepprg by overwriting it whenever :Grep is called with the appropriate tool based on the file and your environment.

Installation

Pick one of the supported alternatives: rg, ag and git-grep

Rg

You have to install rg, of course.

Install with Homebrew:

brew install rg

Ag

You have to install ag, of course.

Install with Homebrew:

brew install the_silver_searcher

Git grep

This comes with git, and will automatically be used when appropriate

Usage

:Grep [options] {pattern} [{directory}]

Search recursively in {directory} (which defaults to the current directory) for the {pattern}.

Files containing the search term will be listed in the split window, along with the line number of the occurrence, once for each occurrence. [Enter] on a line in this window will open the file, and place the cursor on the matching line.

Just like where you use :grep, :grepadd, :lgrep, and :lgrepadd, you can use :Grep, :GrepAdd, :LGrep, and :LGrepAdd respectively.

This plugin is almost copy and pasted from mileszs' ack.vim plugin.

Motion

Motions to grep for things. Works with pretty much everything, including:

w, W, e, E, b, B, t*, f*, i*, a*, and custom text objects

Normal mode

Place your cursor somewhere, type gr and, then perform a text-object for what you want to grep for.

Visual mode

Visually select the pattern you want to grep for, type gr.

Mappings

The mapping gr is set in both normal and visual-mode, if you want to remove it to set your own mappings you set g:grep_no_maps in your .vimrc

If you want to use qq instead of gr:

let g:grep_no_maps = 1
nnoremap <silent> qq :set opfunc=<SID>GrepMotion<CR>g@
xnoremap <silent> qq :<C-U>call <SID>GrepMotion(visualmode())<CR>

Customizing

The following options allow customization of the commands.

let g:vimgrep_rg_command="rg --vimgrep --color=never --no-heading --hidden"
let g:vimgrep_ag_command="ag --vimgrep --color=never --column --hidden"
let g:vimgrep_gitgrep_command="git --no-pager grep -n"

License

Copyright (c) Teo Ljungberg. Distributed under the same terms as Vim itself. See :help license.

About

A utility for grepping that isn't limited to a specific program

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •