vim-commentary icon indicating copy to clipboard operation
vim-commentary copied to clipboard

Add duplicate (yank, comment, and put) operation.

Open jeetsukumaran opened this issue 10 years ago • 9 comments

A common operation is for a section of text to be duplicated and commented out, so that it can be edited/refactored/reworked, while the original is still available for reference until the new version is finalized or otherwise ready for commit. This duplicate + comment operation requires the target text to be specified twice: once for the yanking, and then again for the commenting-out. This patch makes this operation much easier by combining the yanking, commenting, and pasting actions to act on the same target.

Notes:

(1) I am somewhat equivocal on the choice of the key-mapping (gy). Please feel free to change if something better occurs to you, assuming you accept the patch.

(2) I cannot see a use-case where this operation would not be linewise. It should be easy to enough to fix if there is a need/demand for characterwise or blockwise operations.

jeetsukumaran avatar Mar 03 '15 02:03 jeetsukumaran

Can you ditch the duplicate-and-comment documentation (at least temporarily) and squash everything else down to a single commit?

tpope avatar Mar 15 '15 18:03 tpope

Ok, done.

jeetsukumaran avatar Mar 15 '15 18:03 jeetsukumaran

Actually if it's not too much trouble, could you add a second commit restoring the duplicate functionality on gcd? I will play with both for a few days and see what I find most useful.

tpope avatar Mar 15 '15 19:03 tpope

And ... done!

jeetsukumaran avatar Mar 15 '15 19:03 jeetsukumaran

I know this is 4 years old but I would love to see this (or similar) merged.

airblade avatar Aug 30 '19 10:08 airblade

@airblade are you aware of '] and '[? One can already yank and then comment using those marks. E.g. to yank 2 lines then comment those same lines:

yj
gc']

justinmk avatar Aug 30 '19 12:08 justinmk

@justinmk Thanks for the info – yes, I know about '[ and '] but I feel gcd{motion} et al is neater than yanking, pasting, and commenting as three separate activities. I could cobble it together in my vimrc but it would be nice were it built in.

airblade avatar Aug 30 '19 12:08 airblade

@tpope can this please be merged?

nwaywood avatar Sep 09 '20 00:09 nwaywood

I would also still like this feature. I'd also prefer an option that didn't automatically put it -- just yank. Sometimes I want the duplicated code to be in a specific place, so having it auto-put might be more of a hassle than having it yank, and then manually putting it.

evanthegrayt avatar Oct 19 '20 16:10 evanthegrayt