Skip to content

Instantly share code, notes, and snippets.

@rexagod
Last active December 23, 2021 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexagod/839197999d533f90117fb3e108c266ff to your computer and use it in GitHub Desktop.
Save rexagod/839197999d533f90117fb3e108c266ff to your computer and use it in GitHub Desktop.
Grep stuff inside Vim
" grep!
function! s:ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
copen
else
cclose
endif
endfunction
function! s:Grepper(type)
let l:bkreg=@@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[y`]
endif
silent exe "grep! -R " . shellescape(@@) . " *"
let @@=l:bkreg
copen
endfunction
nn <leader>qf :call <SID>ToggleQuickFix()<cr>
nn <leader>gg :set opfunc=<SID>Grepper<cr>g@
vn <leader>gg :<c-u>call <SID>Grepper(visualmode())<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment