aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2023-06-13 09:25:20 +0800
committerAaron LI <aly@aaronly.me>2023-06-13 10:02:50 +0800
commitb2a692842652f27fa06f0d6fed7a5b491b6b46e8 (patch)
tree22ed2ec04d5d044e14ba6788a2cc842a51b02b41
parentfbb14398ea74ddf4f79d9a855536fa606a84087c (diff)
downloaddotfiles-b2a692842652f27fa06f0d6fed7a5b491b6b46e8.tar.bz2
vim: Add config for instant grep + quickfix search
-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