Add duplicate (yank, comment, and put) operation.#42
Add duplicate (yank, comment, and put) operation.#42jeetsukumaran wants to merge 5 commits intotpope:masterfrom
Conversation
|
Can you ditch the duplicate-and-comment documentation (at least temporarily) and squash everything else down to a single commit? |
Support for yanking a section of text before commenting them out. By default, mapped to '`gcy`'.
|
Ok, done. |
|
Actually if it's not too much trouble, could you add a second commit restoring the duplicate functionality on |
Support for duplicating a section of text before commenting them out. By
default, mapped to '`gcd`'.
|
And ... done! |
plugin/commentary.vim
Outdated
There was a problem hiding this comment.
Won't this cause a pause since <Plug>CommentaryDupeLine overlaps <Plug>CommentaryDupe? (solution would be to wrap in parentheses, e.g., <Plug>(CommentaryDupeLine) and <Plug>(CommentaryDupe))
There was a problem hiding this comment.
Good point. In practice, however, it may not be an issue? In normal
mode, where the conflict arises, <Plug>CommentaryDupe takes a motion,
and so there is no pause (except if you count Vim waiting for you to
complete the operator motion). So, you will always be typing either
gcdd or gcd{motion}`. Still, it makes sense to code defensively here
and wrap the names with parentheses, but that will break the convention
with the rest of Plug's, so I am going to wait and see if (a) @tpope
accepts this patch in the first place, and (b) if he amenable to
modifying all the Plug names.
On 3/19/15 6:03 PM, Justin M. Keyes wrote:
In plugin/commentary.vim
#42 (comment):@@ -87,6 +126,12 @@ if !hasmapto('Commentary') || maparg('gc','n') ==# ''
nmap gcc CommentaryLine
nmap cgc ChangeCommentary
nmap gcu CommentaryCommentary
- xmap gcy CommentaryYank
- nmap gcy CommentaryYank
- nmap gcyy CommentaryYankLine
- xmap gcd CommentaryDupe
- nmap gcd CommentaryDupe
Won't this cause a pause since |CommentaryDupeLine| overlaps
|CommentaryDupe|? (solution would be to wrap in parentheses, e.g.,
|(CommentaryDupeLine)| and |(CommentaryDupe)|)—
Reply to this email directly or view it on GitHub
https://github.com/tpope/vim-commentary/pull/42/files#r26802462.
Jeet Sukumaran
jeetsukumaran@gmail.com
Blog/Personal Pages:
http://jeetworks.org/
GitHub Repositories:
http://github.com/jeetsukumaran
Photographs (as stream):
http://www.flickr.com/photos/jeetsukumaran/
Photographs (by galleries):
http://www.flickr.com/photos/jeetsukumaran/sets/
There was a problem hiding this comment.
I am indeed adopting the parentheses convention for new plugins, but I will not be updating old plugins unless there's a concrete issue.
|
I know this is 4 years old but I would love to see this (or similar) merged. |
|
@airblade are you aware of |
|
@justinmk Thanks for the info – yes, I know about |
|
@tpope can this please be merged? |
|
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. |
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.