nerdcommenter icon indicating copy to clipboard operation
nerdcommenter copied to clipboard

Add ability to specify register when yanking

Open jacktose opened this issue 8 months ago • 1 comments

NERDCommenterYank (\cy) yanks to the default unnamed register ". Like all other yanking, this is a good default, this gives the user an option to choose another register. One use case is creating a “comment and duplicate” function/mapping without clobbering the default register, as discussed in #435. Closes #543

Goals

  • ["x][count]\cy - Support standard register specification for NERDCommenterYank mapping, as with ["x]yy and friends.
  • ["x]<plug>NERDCommenterYank, <plug>NERDCommenterYank({register}), or similar way to specify a register when invoking this way (e.g. in a user-defined function or mapping).
    • I'm not sure if this is possible. IMO it's not critical because it can be accomplished by remapping to the default maps: nmap \abc "x\cy
  • NERDComment({mode}, {type}, [{register}]) - Specify register when type=Yank.
    • I'm very reluctant to mess with the main function signature.
  • let g:NERDDefaultRegister = x - Set default register used by NERDCommenterYank.
    • This works. It defaults to " (so no behavior change by default) and is overridden when specifying a register with "x.
  • ✅ Update documentation

Validation

This works for me in vim 9.1. I'm brand new to vim help files, and not much better at vimscript, so additional eyes and feedback are welcome.

jacktose avatar May 06 '25 21:05 jacktose

@alerque Could you take a look?

jacktose avatar Jun 06 '25 18:06 jacktose