@@ -72,6 +72,24 @@ function! s:textobject(inner) abort
7272 endif
7373endfunction
7474
75+ function ! s: setcommentaryreg (reg )
76+ let s: targetreg = a: reg
77+ endfunction
78+ function ! s: yankandcomment (type ,... )
79+ " only linewise operations make sense (to me, at least)
80+ " so I am ignoring `type`
81+ if a: 0
82+ let [mark1, mark2] = [a: type , a: 1 ]
83+ let reg = a: 2
84+ else
85+ let [mark1, mark2] = [" '[" , " ']" ]
86+ let reg = get (s: , " targetreg" , ' "' )
87+ endif
88+ execute ' normal! ' . mark1 . ' "' . reg . ' y' . mark2 . ' ]'
89+ call <SID> go (line (mark1),line (mark2))
90+ execute ' normal! ' . mark1
91+ endfunction
92+
7593xnoremap <silent> <Plug> Commentary :<C-U> call <SID> go(line("'<"),line("'> "))<CR>
7694nnoremap <silent> <Plug> Commentary :<C-U> set opfunc=<SID> go<CR> g@
7795nnoremap <silent> <Plug> CommentaryLine :<C-U> set opfunc=<SID> go<Bar> exe 'norm! 'v:count1.'g@_'<CR>
@@ -80,13 +98,21 @@ nnoremap <silent> <Plug>ChangeCommentary c:<C-U>call <SID>textobject(1)<CR>
8098nmap <silent> <Plug> CommentaryUndo <Plug> Commentary<Plug> Commentary
8199command ! - range - bar Commentary call s: go (<line1> ,<line2> )
82100
101+ xnoremap <silent> <Plug> CommentaryYank :<C-U> call<SID> yankandcomment("'<", "'> ", v:register)<CR>
102+ nnoremap <silent> <Plug> CommentaryYank :<C-U> call <SID> setcommentaryreg(v:register)<CR> :set opfunc=<SID> yankandcomment<CR> g@
103+ nnoremap <silent> <Plug> CommentaryYankLine :<C-U> call <SID> setcommentaryreg(v:register)<CR> :set opfunc=<SID> yankandcomment<Bar> exe 'norm! 'v:count1.'g@_'<CR>
104+
105+ xnoremap <silent> <Plug> Commentary :<C-U> call <SID> go(line("'<"),line("'> "))<CR>
83106if ! hasmapto (' <Plug>Commentary' ) || maparg (' gc' ,' n' ) == # ' '
84107 xmap gc <Plug> Commentary
85108 nmap gc <Plug> Commentary
86109 omap gc <Plug> Commentary
87110 nmap gcc <Plug> CommentaryLine
88111 nmap cgc <Plug> ChangeCommentary
89112 nmap gcu <Plug> Commentary<Plug> Commentary
113+ xmap gcy <Plug> CommentaryYank
114+ nmap gcy <Plug> CommentaryYank
115+ nmap gcyy <Plug> CommentaryYankLine
90116endif
91117
92118if maparg (' \\' ,' n' ) == # ' ' && maparg (' \' ,' n' ) == # ' ' && get (g: , ' commentary_map_backslash' , 1 )
0 commit comments