From b2a692842652f27fa06f0d6fed7a5b491b6b46e8 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 13 Jun 2023 09:25:20 +0800 Subject: vim: Add config for instant grep + quickfix search --- _vim/vimrc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/_vim/vimrc b/_vim/vimrc index c9420e4..45c48bc 100644 --- a/_vim/vimrc +++ b/_vim/vimrc @@ -300,6 +300,24 @@ inoremap vnoremap y "+y noremap 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() +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 + " The Silver Searcher if executable('ag') set grepprg=ag\ --vimgrep -- cgit v1.2.2