Skip to content

Commit

Permalink
Update documentation to show how to duplicate-and-comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetsukumaran committed Mar 13, 2015
1 parent 0b7474c commit d6c75d6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/commentary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <silent> dc :<C-U>call<SID>yankcommentpaste("'<", "'>")<CR>
nnoremap <silent> dc :<C-U>set opfunc=<SID>yankcommentpaste<CR>g@
nnoremap <silent> dcc :<C-U>set opfunc=<SID>yankcommentpaste<Bar>exe 'norm! 'v:count1.'g@_'<CR>
<
The |User| CommentaryPost autocommand fires after a successful operation and
can be used for advanced customization.

Expand Down

0 comments on commit d6c75d6

Please sign in to comment.