feat(prog/vim): add grep op plugin

This commit is contained in:
Dmitriy Pleshevskiy 2022-04-03 20:59:43 +03:00
parent b1ed687e50
commit 4b54861f0b
2 changed files with 28 additions and 0 deletions

5
.gitignore vendored
View File

@ -3,5 +3,10 @@
!/.gitignore
!/programs
/programs/nvim/*
!/programs/nvim/init.vim
!/programs/nvim/plugins
/programs/tmux/*
!/programs/tmux/.tmux.conf

View File

@ -0,0 +1,23 @@
nnoremap <leader>g :set operatorfunc=<SID>GrepOperator<cr>g@
vnoremap <leader>g :<c-u>call <SID>GrepOperator(visualmode())<cr>
nnoremap <leader>cj :cnext<cr>
nnoremap <leader>ck :cprev<cr>
function! s:GrepOperator(type)
let saved_unnamed_register = @@
if a:type ==# 'v'
exe "normal! `<v`>y"
elseif a:type ==# 'char'
exe "normal! `[v`]y"
else
return
endif
silent exe ":grep! -R " . shellescape(@@) . " ."
copen
let @@ = saved_unnamed_register
endfunction