blob: 62a001352c4e8761364a1e13b3e3598dd6861552 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
" A small plugin to replace a text object with the contents of a register.
"
" This is invoked with the 'cp' command. For example
"
" cpiw - replace the inner word with the contents of the default register
" "ncpiw - replace the inner word with the contents of register 'n'
"
" Notably, this command does not alter the contents of the default register, so
" this command may be repeated without worry for changing the editor state.
noremap <silent> cp <cmd>call <sid>setcpreg(v:register)<bar>set operatorfunc=<sid>put<cr>g@
let s:savereg = ''
let s:cpbuf = '"'
function! s:setcpreg(r) abort
let s:cpbuf = a:r
endfunction
function! s:put(arg, ...) abort
if a:0
echo a:1
let vis = '`<' . a:arg . '`>'
elseif a:arg == 'line'
let vis = "'[V']"
elseif a:arg == 'block'
let vis = "`[\<C-v>`]"
else
let vis = "`[v`]"
endif
let save = getreg('"')
silent! exec printf("norm %s\"%sp", vis, s:cpbuf)
call setreg('"', save)
endfunction
|