From 09da0b6a7e5464c261341a8c33297b5ce747c3dc Mon Sep 17 00:00:00 2001 From: Jack Haden-Enneking Date: Tue, 6 May 2025 13:38:09 -0700 Subject: [PATCH 1/3] make Yank respect prepended register --- autoload/nerdcommenter.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/nerdcommenter.vim b/autoload/nerdcommenter.vim index 53935fb..d307b2c 100644 --- a/autoload/nerdcommenter.vim +++ b/autoload/nerdcommenter.vim @@ -1291,11 +1291,11 @@ function! nerdcommenter#Comment(mode, type) range abort elseif a:type ==? 'Yank' if isVisual - normal! gvy + execute 'normal! gv"'. v:register . 'y' elseif countWasGiven - execute firstLine .','. lastLine .'yank' + execute firstLine .','. lastLine .'yank '. v:register else - normal! yy + execute 'normal! "'. v:register .'yy' endif execute firstLine .','. lastLine .'call nerdcommenter#Comment("'. a:mode .'", "Comment")' endif From 38d8b8a6e644c8247d4bc624f61eb6d31c3257fa Mon Sep 17 00:00:00 2001 From: Jack Haden-Enneking Date: Tue, 6 May 2025 14:23:42 -0700 Subject: [PATCH 2/3] add default register setting g:NERDDefaultRegister --- autoload/nerdcommenter.vim | 7 ++++--- plugin/nerdcommenter.vim | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/autoload/nerdcommenter.vim b/autoload/nerdcommenter.vim index d307b2c..d50e15d 100644 --- a/autoload/nerdcommenter.vim +++ b/autoload/nerdcommenter.vim @@ -1290,12 +1290,13 @@ function! nerdcommenter#Comment(mode, type) range abort call s:UncommentLines(firstLine, lastLine) elseif a:type ==? 'Yank' + let l:register = (v:register ==? '"' ? g:NERDDefaultRegister : v:register) if isVisual - execute 'normal! gv"'. v:register . 'y' + execute 'normal! gv"'. l:register . 'y' elseif countWasGiven - execute firstLine .','. lastLine .'yank '. v:register + execute firstLine .','. lastLine .'yank '. l:register else - execute 'normal! "'. v:register .'yy' + execute 'normal! "'. l:register .'yy' endif execute firstLine .','. lastLine .'call nerdcommenter#Comment("'. a:mode .'", "Comment")' endif diff --git a/plugin/nerdcommenter.vim b/plugin/nerdcommenter.vim index e47636b..066208d 100644 --- a/plugin/nerdcommenter.vim +++ b/plugin/nerdcommenter.vim @@ -43,6 +43,7 @@ call s:InitVariable('g:NERDTrimTrailingWhitespace', 0) call s:InitVariable('g:NERDToggleCheckAllLines', 0) call s:InitVariable('g:NERDDisableTabsInBlockComm', 0) call s:InitVariable('g:NERDSuppressWarnings', 0) +call s:InitVariable('g:NERDDefaultRegister', '"') " Section: Comment mapping and menu item setup " =========================================================================== From b22a127ab0db31a27bd1b7d888fac9eade0e2027 Mon Sep 17 00:00:00 2001 From: Jack Haden-Enneking Date: Tue, 6 May 2025 16:26:53 -0700 Subject: [PATCH 3/3] update docs --- README.md | 5 ++++- doc/nerdcommenter.txt | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 39a77c6..502fa7b 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,9 @@ let g:NERDTrimTrailingWhitespace = 1 " Enable NERDCommenterToggle to check all selected lines is commented or not let g:NERDToggleCheckAllLines = 1 + +" Make NERDCommentYank write to a specific register by default, instead of `""` +let g:NERDDefaultRegister = 'c' ``` ### Default mappings @@ -172,7 +175,7 @@ Most of the following mappings are for normal/visual mode only. The **|NERDComme * `[count]cy` **|NERDCommenterYank|** - Same as cc except that the commented line(s) are yanked first. + Same as cc except that it first yanks the commented line(s) [into register x]. * `c$` **|NERDCommenterToEOL|** diff --git a/doc/nerdcommenter.txt b/doc/nerdcommenter.txt index 3f465b3..e368648 100644 --- a/doc/nerdcommenter.txt +++ b/doc/nerdcommenter.txt @@ -126,8 +126,9 @@ Toggles the comment state of the selected line(s) individually. Comments out the selected lines ``sexily'' -[count]||cy |NERDCommenterYank| -Same as ||cc except that the commented line(s) are yanked first. +["x][count]||cy |NERDCommenterYank| +Same as ||cc except that it first yanks the commented line(s) [into +register x]. ||c$ |NERDCommenterToEOL| @@ -280,11 +281,15 @@ Related options: ------------------------------------------------------------------------------ 3.2.7 Yank comment map *NERDCommenterYank* -Default mapping: [count]||cy +Default mapping: ["x]|[count]||cy Mapped to: NERDCommenterYank Applicable modes: normal visual visual-line visual-block. -Same as ||cc except that it yanks the line(s) that are commented first. +Same as ||cc except that it first yanks the commented line(s) [into +register x]. + +Related options: +|'NERDDefaultRegister'| ------------------------------------------------------------------------------ 3.2.8 Comment to EOL map *NERDCommenterToEOL* @@ -509,6 +514,9 @@ change the filetype back: > |'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check all selected lines is commented or not. +|'NERDDefaultRegister'| Specifies which register + |NERDCommenterYank| yanks to. + ------------------------------------------------------------------------------ 4.2 Options details *NERDCommenterOptionsDetails* @@ -813,7 +821,7 @@ As opposed to like this: > If this option is set to 1 then the top style will be used. ------------------------------------------------------------------------------ - *'NERDDefaultNesting'* + *'NERDDefaultNesting'* Values: 0 or 1. Default 1. @@ -854,6 +862,16 @@ file by the following line > \ } < +------------------------------------------------------------------------------ + *'NERDDefaultRegister'* +Values: single-character string. +Default '"'. + +|NERDCommenterYank| will yank to this register, unless another is specified +with ["x]. + +See |registers| for available register names and other details. + ------------------------------------------------------------------------------ 4.3 Default delimiter customisation *NERDCommenterDefaultDelims*