@@ -1035,6 +1035,50 @@ function s:InvertComment(firstLine, lastLine)
1035
1035
endwhile
1036
1036
endfunction
1037
1037
1038
+ " Function: NERDCommentYank(mode, type) function {{{2
1039
+ " This function handles yanking
1040
+ "
1041
+ " Args:
1042
+ " -mode: a flag indicating whether the comment is requested in visual
1043
+ " mode or not
1044
+ " -register: the register to yank into
1045
+ function NERDCommentYank (mode , register ) range
1046
+ let isVisual = a: mode = ~ ' [vsx]'
1047
+ if isVisual
1048
+ let firstLine = line (" '<" )
1049
+ let lastLine = line (" '>" )
1050
+ let firstCol = col (" '<" )
1051
+ let lastCol = col (" '>" ) - (&selection == ' exclusive' ? 1 : 0 )
1052
+ else
1053
+ let firstLine = a: firstline
1054
+ let lastLine = a: lastline
1055
+ endif
1056
+
1057
+ let reg = ' '
1058
+ let range = ' '
1059
+ let rangeCount = ' '
1060
+
1061
+ if a: register != " "
1062
+ let reg = ' "' .a: register
1063
+ endif
1064
+
1065
+ if firstLine != lastLine
1066
+ let range = firstLine .' ,' . lastLine
1067
+ let rangeCount = lastLine - firstLine + 1
1068
+ endif
1069
+
1070
+ if isVisual
1071
+ normal ! gvy
1072
+ else
1073
+ execute range .' yank ' . a: register
1074
+ endif
1075
+ execute range .' call NERDComment(' . a: mode .' , "Comment")'
1076
+
1077
+ if ! isVisual
1078
+ silent ! call repeat#set (rangeCount.reg .' \<plug>NERDCommenterYank' ,-1 )
1079
+ endif
1080
+ endfunction
1081
+
1038
1082
" Function: NERDComment(mode, type) function {{{2
1039
1083
" This function is a Wrapper for the main commenting functions
1040
1084
"
@@ -1043,7 +1087,7 @@ endfunction
1043
1087
" 'n' for Normal mode, 'x' for Visual mode
1044
1088
" -type: the type of commenting requested. Can be 'Sexy', 'Invert',
1045
1089
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
1046
- " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
1090
+ " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment'
1047
1091
function ! NERDComment (mode , type ) range
1048
1092
let isVisual = a: mode = ~ ' [vsx]'
1049
1093
" we want case sensitivity when commenting
@@ -1064,8 +1108,6 @@ function! NERDComment(mode, type) range
1064
1108
let lastLine = a: lastline
1065
1109
endif
1066
1110
1067
- let countWasGiven = (! isVisual && firstLine != lastLine)
1068
-
1069
1111
let forceNested = (a: type == ? ' Nested' || g: NERDDefaultNesting )
1070
1112
1071
1113
if a: type == ? ' Comment' || a: type == ? ' Nested'
@@ -1130,15 +1172,6 @@ function! NERDComment(mode, type) range
1130
1172
elseif a: type == ? ' Uncomment'
1131
1173
call s: UncommentLines (firstLine, lastLine)
1132
1174
1133
- elseif a: type == ? ' Yank'
1134
- if isVisual
1135
- normal ! gvy
1136
- elseif countWasGiven
1137
- execute firstLine .' ,' . lastLine .' yank'
1138
- else
1139
- normal ! yy
1140
- endif
1141
- execute firstLine .' ,' . lastLine .' call NERDComment("' . a: mode .' ", "Comment")'
1142
1175
endif
1143
1176
1144
1177
let &ignorecase = oldIgnoreCase
@@ -2720,8 +2753,15 @@ function! s:CreateMaps(modes, target, desc, combo)
2720
2753
" Build up a map command like
2721
2754
" 'noremap <silent> <plug>NERDCommenterComment :call NERDComment("n", "Comment")'
2722
2755
let plug = ' <plug>NERDCommenter' . a: target
2723
- let plug_start = ' noremap <silent> ' . plug . ' :call NERDComment("'
2724
- let plug_end = ' ", "' . a: target . ' ")<cr>'
2756
+ if a: target == ? ' Yank'
2757
+ let func_name = ' NERDCommentYank'
2758
+ let target = ' v:register'
2759
+ else
2760
+ let func_name = ' NERDComment'
2761
+ let target = " '" . a: target . " '"
2762
+ endif
2763
+ let plug_start = ' noremap <silent> ' . plug . ' :call ' . func_name . ' ("'
2764
+ let plug_end = ' ", "' . target . ' ")<cr>'
2725
2765
" Build up a menu command like
2726
2766
" 'menu <silent> comment.Comment<Tab>\\cc <plug>NERDCommenterComment'
2727
2767
let menuRoot = get ([' ' , ' comment' , ' &comment' , ' &Plugin.&comment' ],
0 commit comments