Skip to content

example configurations and mappings

Marco Hinz edited this page Nov 14, 2016 · 9 revisions

Example configuration

nnoremap <leader>g :Grepper -tool git<cr>
nnoremap <leader>G :Grepper -tool ag<cr>

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

" Optional. The default behaviour should work for most users.
let g:grepper               = {}
let g:grepper.tools         = ['git', 'ag', 'rg']
let g:grepper.jump          = 1
let g:grepper.next_tool     = '<leader>g'
let g:grepper.simple_prompt = 1
let g:grepper.quickfix      = 0

Example mappings

Don't open the quickfix window and jump to the first match right away:

nnoremap <leader>g :Grepper -tool git -noopen -jump<cr>

Start searching the word under the cursor:

nnoremap <leader>* :Grepper -tool ag -cword -noprompt<cr>

Different mappings for searching from the working directory and searching only those files opened in Vim:

nnoremap <leader>g :Grepper -tool rg<cr>
nnoremap <leader>G :Grepper -tool rg -buffers<cr>

Example commands

Find all occurrences of TODO and FIXME. (-query searches right away, no -noprompt needed.)

command! Todo :Grepper -tool git -query '\(TODO\|FIXME\)'

If you want to provide other options as well, use -grepprg to specify the exact command. Pro tip: test in your shell first and use the command 1:1 after -grepprg.

command! Todo :Grepper -noprompt -tool git -grepprg git grep -nIi '\(TODO\|FIXME\)'

If you find that hard to read, you can use multiple lines like this:

command! Todo :Grepper
      \ -noprompt
      \ -tool git
      \ -grepprg git grep -nIi '\(TODO\|FIXME\)'
Clone this wiki locally