set grepprg=ag\ --vimgrep function! Grep(...) return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' ')) endfunction command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep() command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep() cnoreabbrev grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep' cnoreabbrev lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep' augroup quickfix autocmd! autocmd QuickFixCmdPost cgetexpr cwindow autocmd QuickFixCmdPost lgetexpr lwindow augroup END