Last active
December 23, 2021 08:43
-
-
Save rexagod/839197999d533f90117fb3e108c266ff to your computer and use it in GitHub Desktop.
Grep stuff inside Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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