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/autoload/nerdcommenter.vim b/autoload/nerdcommenter.vim index 53935fb..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 - normal! gvy + execute 'normal! gv"'. l:register . 'y' elseif countWasGiven - execute firstLine .','. lastLine .'yank' + execute firstLine .','. lastLine .'yank '. l:register else - normal! yy + execute 'normal! "'. l:register .'yy' endif execute firstLine .','. lastLine .'call nerdcommenter#Comment("'. a:mode .'", "Comment")' endif 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* 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 " ===========================================================================