aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_vim/vimrc18
1 files changed, 18 insertions, 0 deletions
diff --git a/_vim/vimrc b/_vim/vimrc
index c9420e4..45c48bc 100644
--- a/_vim/vimrc
+++ b/_vim/vimrc
@@ -300,6 +300,24 @@ inoremap <F1> <Esc>
vnoremap <leader>y "+y
noremap <leader>p "+p
+" Instant grep + quickfix
+" https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3
+function! Grep(...)
+ return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' '))
+endfunction
+"
+command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep(<f-args>)
+command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
+"
+cnoreabbrev <expr> grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep'
+cnoreabbrev <expr> lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep'
+"
+augroup quickfix
+ autocmd!
+ autocmd QuickFixCmdPost cgetexpr cwindow
+ autocmd QuickFixCmdPost lgetexpr lwindow
+augroup END
+
" The Silver Searcher
if executable('ag')
set grepprg=ag\ --vimgrep