From d6c75d6ef0ba81f0e2d67c6fdb147d1b8d005628 Mon Sep 17 00:00:00 2001 From: Jeet Sukumaran Date: Fri, 13 Mar 2015 13:22:10 -0400 Subject: [PATCH] Update documentation to show how to duplicate-and-comment. --- doc/commentary.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/commentary.txt b/doc/commentary.txt index f026eae..e436372 100644 --- a/doc/commentary.txt +++ b/doc/commentary.txt @@ -39,6 +39,25 @@ gcy Yank and then comment or uncomment [count] lines. {Visual}gcy Yank and then comment or uncomment the highlighted lines. +You can implement a "duplicate-and-comment" operation, i.e., where text is +yanked, commented/uncommented, and then the original text is pasted again by +something like the following: > + + function! s:yankcommentpaste(type,...) + if a:0 + let [mark1, mark2] = [a:type, a:1] + else + let [mark1, mark2] = ["'[", "']"] + endif + let savereg = @" + execute "normal " . mark1 ."gcy" . mark2 . "]" + execute "normal! " . mark2 . "p" . mark1 + let @" = savereg + endfunction + xnoremap dc :callyankcommentpaste("'<", "'>") + nnoremap dc :set opfunc=yankcommentpasteg@ + nnoremap dcc :set opfunc=yankcommentpasteexe 'norm! 'v:count1.'g@_' +< The |User| CommentaryPost autocommand fires after a successful operation and can be used for advanced customization.