@@ -72,6 +72,24 @@ function! s:textobject(inner) abort
72
72
endif
73
73
endfunction
74
74
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
+
75
93
xnoremap <silent> <Plug> Commentary :<C-U> call <SID> go(line("'<"),line("'> "))<CR>
76
94
nnoremap <silent> <Plug> Commentary :<C-U> set opfunc=<SID> go<CR> g@
77
95
nnoremap <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>
80
98
nmap <silent> <Plug> CommentaryUndo <Plug> Commentary<Plug> Commentary
81
99
command ! - range - bar Commentary call s: go (<line1> ,<line2> )
82
100
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>
83
106
if ! hasmapto (' <Plug>Commentary' ) || maparg (' gc' ,' n' ) == # ' '
84
107
xmap gc <Plug> Commentary
85
108
nmap gc <Plug> Commentary
86
109
omap gc <Plug> Commentary
87
110
nmap gcc <Plug> CommentaryLine
88
111
nmap cgc <Plug> ChangeCommentary
89
112
nmap gcu <Plug> Commentary<Plug> Commentary
113
+ xmap gcy <Plug> CommentaryYank
114
+ nmap gcy <Plug> CommentaryYank
115
+ nmap gcyy <Plug> CommentaryYankLine
90
116
endif
91
117
92
118
if maparg (' \\' ,' n' ) == # ' ' && maparg (' \' ,' n' ) == # ' ' && get (g: , ' commentary_map_backslash' , 1 )
0 commit comments