Skip to content

mhinz/vim-grepper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-grepper

vim-grepper

If you use any of my plugins, please star them on github. It’s a great way of getting feedback and gives me the kick to put more time into their development. If you encounter any bugs or have feature requests, just open an issue report on Github.

Follow me: Twitter

Intro

This plugin is a convenience wrapper around 'grepprg' and 'grepformat', supports most common grep tools, and is easily extendable. It exposes a single command: :Grepper.

You choose a grep tool, enter a search term, and get your matches into a quickfix list.


Features:

  • supports by default: git grep, ag, pt, ack, grep, findstr

  • quick switching between grep tools

  • adding new grep tools or replacing parameters of default ones is easy

  • asynchronous search with Neovim or vim-dispatch

  • operator for selecting search queries by motion

  • operator action is repeatable if vim-repeat is installed

  • :Grepper takes flags that overrule options (thus you can use different mappings for different configurations)

  • emits an User event when a search finishes, for further customization

  • support for proper statusline plugins

Tip
Read :h grepper for the whole truth.

Examples

:Grepper takes a number of flags which makes it a very versatile command.

Example 1:

Create mappings with :Grepper and provide different configurations at the same time:

nnoremap <leader>git :Grepper  -tool git -open -nojump<cr>
nnoremap <leader>ag  :Grepper! -tool ag  -open -switch<cr>
nnoremap <leader>*   :Grepper! -tool ack -cword<cr>

These first two mappings will fire up the search prompt with the provided configuration. The third one will open the prompt prepopulated with the word under the cursor.

Example 2:

Use the operator to search for text from the current buffer:

nmap gs <plug>(GrepperOperator)
xmap gs <plug>(GrepperOperator)

gs in visual mode will simply prepopulate the prompt with the current visual selection. You can also use text objects to preopulate the prompt, e.g. gs$ for everything from the current cursor position until the end of the line.

Everytime the prompt gets prepopulated, the query will get escaped according to the used grep tool.

Example 3:

You can use :Grepper to build your own commmands:

command! -nargs=* -complete=file GG Grepper! -tool git -query <args>
command! -nargs=* -complete=file Ag Grepper! -tool ag -query <args>

Now you can use it like this: :Ag foo or :GG 'foo bar' *.txt. Mind that <tab> can be used for file completion, too.

Installation and Documentation

If you don’t have a plugin manager, I suggest having a look at vim-plug. Installation is a breeze afterwards:

Plug 'mhinz/vim-grepper'
Plug 'tpope/vim-dispatch'  " optional
Plug 'tpope/vim-repeat'    " optional

Restart Vim or :source $MYVIMRC, then do :PlugInstall.

License

MIT license. Copyright (c) 2015 Marco Hinz.

Packages

No packages published

Contributors 25