Skip to content

Commit d6c75d6

Browse files
committed
Update documentation to show how to duplicate-and-comment.
1 parent 0b7474c commit d6c75d6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/commentary.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ gcy Yank and then comment or uncomment [count] lines.
3939
{Visual}gcy Yank and then comment or uncomment the highlighted
4040
lines.
4141

42+
You can implement a "duplicate-and-comment" operation, i.e., where text is
43+
yanked, commented/uncommented, and then the original text is pasted again by
44+
something like the following: >
45+
46+
function! s:yankcommentpaste(type,...)
47+
if a:0
48+
let [mark1, mark2] = [a:type, a:1]
49+
else
50+
let [mark1, mark2] = ["'[", "']"]
51+
endif
52+
let savereg = @"
53+
execute "normal " . mark1 ."gcy" . mark2 . "]"
54+
execute "normal! " . mark2 . "p" . mark1
55+
let @" = savereg
56+
endfunction
57+
xnoremap <silent> dc :<C-U>call<SID>yankcommentpaste("'<", "'>")<CR>
58+
nnoremap <silent> dc :<C-U>set opfunc=<SID>yankcommentpaste<CR>g@
59+
nnoremap <silent> dcc :<C-U>set opfunc=<SID>yankcommentpaste<Bar>exe 'norm! 'v:count1.'g@_'<CR>
60+
<
4261
The |User| CommentaryPost autocommand fires after a successful operation and
4362
can be used for advanced customization.
4463

0 commit comments

Comments
 (0)