Skip to content

Add a tool

Marco Hinz edited this page Nov 17, 2016 · 7 revisions

Basics

If you don't like the default arguments to a grep tool or you want to add a new one, just add/replace the key to g:grepper:

let g:grepper = {
    \ 'tools': ['pt', 'git'],
    \ 'pt': {
    \   'grepprg':    'pt --nocolor --nogroup',
    \   'grepformat': '%f:%l:%m',
    \   'escape':     '\+*^$()[]',
    \ }}

tools

These are the tools that you can choose between. The order matters. The first element is the default tool and will be used if no tool was specified.

Defaults to: ['ag', 'ack', 'grep', 'findstr', 'rg', 'pt', 'git']

Because of a name clash, some systems use "ack-grep" instead of "ack". If you include "ack" here, "ack-grep" will be found, too.

grepprg

The tool has be executable, but it doesn't have to be in $PATH. This works just as well:

'grepprg': '~/bin/greppy -a -b --c'

In cases where the arguments don't come last, use $* as a placeholder:

'grepprg': 'grep -Rn $* .'

If you want to use the tool on all currently opened files (instead of the current directory), use $+ as a placeholder:

'grepprg': 'ag --vimgrep $* $+'

If you want to use the tool only on the current file, use $. as a placeholder:

'grepprg': 'ag --vimgrep $* $.'

grepprgbuf

In the case of -buffer, 'grepprgbuf' is used. If it doesn't exist, $* $. will be appended to 'grepprg' instead.

Same goes for -buffers, only that $. will be replaced by $+.

grepformat

This is optional. If the output of 'grepprg' uses a format that is not already recognized by the default grepformat, define it yourself here. See :h 'grepformat'.

escape

This is optional. All these characters will be escaped in the query.

Advanced example: :vimgrep

This is a bit of a hack, but you could even use an async :vimgrep like this:

let g:grepper = {
      \ 'tools': ['git', 'ag', 'vimgrep'],
      \ 'vimgrep': {
      \   'grepprg':    "vim -es +'vimgrep /$*/ ** | cw | %p | qa'",
      \   'grepprgbuf': "vim -es +'vimgrep /$*/ $. | cw | %p | qa'",
      \   'grepformat': '%f|%l col %c|%m' }}

Depending on your vimrc, you might need to prepend grepprg/grepprgbuf with set nonumber norelativenumber | etc.

Everything but the operator works with these settings.

Clone this wiki locally