feat(prog/vim): add grep op plugin
This commit is contained in:
parent
b1ed687e50
commit
4b54861f0b
2 changed files with 28 additions and 0 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -3,5 +3,10 @@
|
|||
!/.gitignore
|
||||
|
||||
!/programs
|
||||
|
||||
/programs/nvim/*
|
||||
!/programs/nvim/init.vim
|
||||
!/programs/nvim/plugins
|
||||
|
||||
/programs/tmux/*
|
||||
!/programs/tmux/.tmux.conf
|
||||
|
|
23
programs/nvim/plugins/grep-operator.vim
Normal file
23
programs/nvim/plugins/grep-operator.vim
Normal 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
|
||||
|
Loading…
Reference in a new issue