Instant grep + quickfix

2 Points

Romain Lafourcade Romain Lafourcade

5 years ago

Instant grep + quickfix

" Tell Vim what external program to use for grepping.
set grepprg=ag\ --vimgrep

" Open the location/quickfix window automatically if there are valid entries in the list.
augroup quickfix
	autocmd QuickFixCmdPost cgetexpr cwindow
	autocmd QuickFixCmdPost lgetexpr lwindow
augroup END

" Use :Grep instead of :grep! and :LGrep instead of :lgrep!.
" :cgetexpr and :lgetexpr are much faster than :grep and :lgrep
" and they don't mess with your terminal emulator.
command! -nargs=+ -complete=file_in_path -bar Grep  cgetexpr system(&grepprg . ' ' . shellescape(<q-args>))
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr system(&grepprg . ' ' . shellescape(<q-args>))