Skip to content

Instantly share code, notes, and snippets.

@andlrc
Created May 2, 2023 17:34
Show Gist options
  • Save andlrc/c8e1a3b9c1ec5c761111ea0e49bda6c4 to your computer and use it in GitHub Desktop.
Save andlrc/c8e1a3b9c1ec5c761111ea0e49bda6c4 to your computer and use it in GitHub Desktop.
" dyngrepprg - set "grepprg" to dynamically when inside a git repository
" Maintainer: Andreas Louv <andreas@louv.dk>
" Date: 3 Aug 2018
augroup DynGrepPrg
au!
au DirChanged * call <SID>SetGrepPrg()
augroup END
function! s:SetGrepPrg()
if system('git rev-parse --show-toplevel 2> /dev/null') !~ '^\s*$'
set grepprg=git\ grep\ -n\ --column\ $*
else
set grepprg=grep\ -nH\ --exclude={\\*.o,tags}
\\ --exclude-dir={node_modules,.git}
\\ $*
endif
endfunction
call s:SetGrepPrg()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment