@@ -26,17 +26,29 @@ endfunction
26
26
27
27
function ! s: go (... ) abort
28
28
if ! a: 0
29
- let &operatorfunc = matchstr ( expand (' <sfile >' ), ' [^. ]*$ ' )
29
+ let &operatorfunc = expand (' <SID >' ) . ' go '
30
30
return ' g@'
31
- elseif a: 0 > 1
32
- let [lnum1, lnum2] = [a: 1 , a: 2 ]
33
- else
34
- let [lnum1, lnum2] = [line (" '[" ), line (" ']" )]
35
31
endif
36
32
33
+ let [l1, l2] = a: 0 > 1 ? [a: 1 , a: 2 ] : [line (" '[" ), line (" ']" )]
34
+ call s: apply (l1, l2)
35
+ endfunction
36
+
37
+ function ! s: yank (... ) abort
38
+ if ! a: 0
39
+ let &operatorfunc = expand (' <SID>' ) . ' yank'
40
+ return ' g@'
41
+ endif
42
+
43
+ let [l1, l2] = a: 0 > 1 ? [a: 1 , a: 2 ] : [line (" '[" ), line (" ']" )]
44
+ execute l1 . ' ,' . l2 . ' yank' v: register
45
+ call s: apply (l1, l2)
46
+ endfunction
47
+
48
+ function ! s: apply (lnum1, lnum2) abort
37
49
let [l , r ] = s: surroundings ()
38
50
let uncomment = 2
39
- for lnum in range (lnum1,lnum2)
51
+ for lnum in range (a: lnum1 ,a: lnum2 )
40
52
let line = matchstr (getline (lnum),' \S.*\s\@<!' )
41
53
let [l , r ] = s: strip_white_space (l ,r ,line )
42
54
if len (line ) && (stridx (line ,l ) || line [strlen (line )- strlen (r ) : -1 ] != r )
@@ -50,7 +62,7 @@ function! s:go(...) abort
50
62
let indent = ' ^\s*'
51
63
endif
52
64
53
- for lnum in range (lnum1,lnum2)
65
+ for lnum in range (a: lnum1 ,a: lnum2 )
54
66
let line = getline (lnum)
55
67
if strlen (r ) > 2 && l .r !~# ' \\'
56
68
let line = substitute (line ,
@@ -60,7 +72,7 @@ function! s:go(...) abort
60
72
if uncomment
61
73
let line = substitute (line ,' \S.*\s\@<!' ,' \=submatch(0)[strlen(l):-strlen(r)-1]' ,' ' )
62
74
else
63
- let line = substitute (line ,' ^\%(' .matchstr (getline (lnum1),indent ).' \|\s*\)\zs.*\S\@<=' ,' \=l.submatch(0).r' ,' ' )
75
+ let line = substitute (line ,' ^\%(' .matchstr (getline (a: lnum1 ),indent ).' \|\s*\)\zs.*\S\@<=' ,' \=l.submatch(0).r' ,' ' )
64
76
endif
65
77
call setline (lnum,line )
66
78
endfor
@@ -102,12 +114,18 @@ nnoremap <expr> <Plug>CommentaryLine <SID>go() . '_'
102
114
onoremap <silent> <Plug> Commentary :<C-U> call <SID> textobject(get(v:, 'operator', '') ==# 'c')<CR>
103
115
nnoremap <silent> <Plug> ChangeCommentary c:<C-U> call <SID> textobject(1)<CR>
104
116
nmap <silent> <Plug> CommentaryUndo :echoerr "Change your <Plug> CommentaryUndo map to <Plug> Commentary<Plug> Commentary"<CR>
117
+ xnoremap <expr> <Plug> (CommentaryYank) <SID> yank()
118
+ nnoremap <expr> <Plug> (CommentaryYank) <SID> yank()
119
+ nnoremap <expr> <Plug> (CommentaryYankLine) <SID> yank() . '_'
105
120
106
121
if ! hasmapto (' <Plug>Commentary' ) || maparg (' gc' ,' n' ) == # ' '
107
122
xmap gc <Plug> Commentary
108
123
nmap gc <Plug> Commentary
109
124
omap gc <Plug> Commentary
110
125
nmap gcc <Plug> CommentaryLine
126
+ xmap gy <Plug> (CommentaryYank)
127
+ nmap gy <Plug> (CommentaryYank)
128
+ nmap gyy <Plug> (CommentaryYankLine)
111
129
if maparg (' c' ,' n' ) == # ' ' && ! exists (' v:operator' )
112
130
nmap cgc <Plug> ChangeCommentary
113
131
endif
0 commit comments