@@ -1065,6 +1065,50 @@ function s:InvertComment(firstLine, lastLine)
1065
1065
endwhile
1066
1066
endfunction
1067
1067
1068
+ " Function: NERDCommentYank(mode, type) function {{{2
1069
+ " This function handles yanking
1070
+ "
1071
+ " Args:
1072
+ " -mode: a flag indicating whether the comment is requested in visual
1073
+ " mode or not
1074
+ " -register: the register to yank into
1075
+ function NERDCommentYank (mode , register ) range
1076
+ let isVisual = a: mode = ~ ' [vsx]'
1077
+ if isVisual
1078
+ let firstLine = line (" '<" )
1079
+ let lastLine = line (" '>" )
1080
+ let firstCol = col (" '<" )
1081
+ let lastCol = col (" '>" ) - (&selection == ' exclusive' ? 1 : 0 )
1082
+ else
1083
+ let firstLine = a: firstline
1084
+ let lastLine = a: lastline
1085
+ endif
1086
+
1087
+ let reg = ' '
1088
+ let range = ' '
1089
+ let rangeCount = ' '
1090
+
1091
+ if a: register != " "
1092
+ let reg = ' "' .a: register
1093
+ endif
1094
+
1095
+ if firstLine != lastLine
1096
+ let range = firstLine .' ,' . lastLine
1097
+ let rangeCount = lastLine - firstLine + 1
1098
+ endif
1099
+
1100
+ if isVisual
1101
+ normal ! gvy
1102
+ else
1103
+ execute range .' yank ' . a: register
1104
+ endif
1105
+ execute range .' call NERDComment(' . a: mode .' , "Comment")'
1106
+
1107
+ if ! isVisual
1108
+ silent ! call repeat#set (rangeCount.reg .' \<plug>NERDCommenterYank' ,-1 )
1109
+ endif
1110
+ endfunction
1111
+
1068
1112
" Function: NERDComment(mode, type) function {{{2
1069
1113
" This function is a Wrapper for the main commenting functions
1070
1114
"
@@ -1073,7 +1117,7 @@ endfunction
1073
1117
" 'n' for Normal mode, 'x' for Visual mode
1074
1118
" -type: the type of commenting requested. Can be 'Sexy', 'Invert',
1075
1119
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
1076
- " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
1120
+ " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment'
1077
1121
function ! NERDComment (mode , type ) range
1078
1122
let isVisual = a: mode = ~ ' [vsx]'
1079
1123
" we want case sensitivity when commenting
@@ -1094,8 +1138,6 @@ function! NERDComment(mode, type) range
1094
1138
let lastLine = a: lastline
1095
1139
endif
1096
1140
1097
- let countWasGiven = (! isVisual && firstLine != lastLine)
1098
-
1099
1141
let forceNested = (a: type == ? ' Nested' || g: NERDDefaultNesting )
1100
1142
1101
1143
if a: type == ? ' Comment' || a: type == ? ' Nested'
@@ -1160,15 +1202,6 @@ function! NERDComment(mode, type) range
1160
1202
elseif a: type == ? ' Uncomment'
1161
1203
call s: UncommentLines (firstLine, lastLine)
1162
1204
1163
- elseif a: type == ? ' Yank'
1164
- if isVisual
1165
- normal ! gvy
1166
- elseif countWasGiven
1167
- execute firstLine .' ,' . lastLine .' yank'
1168
- else
1169
- normal ! yy
1170
- endif
1171
- execute firstLine .' ,' . lastLine .' call NERDComment("' . a: mode .' ", "Comment")'
1172
1205
endif
1173
1206
1174
1207
let &ignorecase = oldIgnoreCase
@@ -2750,8 +2783,15 @@ function! s:CreateMaps(modes, target, desc, combo)
2750
2783
" Build up a map command like
2751
2784
" 'noremap <silent> <plug>NERDCommenterComment :call NERDComment("n", "Comment")'
2752
2785
let plug = ' <plug>NERDCommenter' . a: target
2753
- let plug_start = ' noremap <silent> ' . plug . ' :call NERDComment("'
2754
- let plug_end = ' ", "' . a: target . ' ")<cr>'
2786
+ if a: target == ? ' Yank'
2787
+ let func_name = ' NERDCommentYank'
2788
+ let target = ' v:register'
2789
+ else
2790
+ let func_name = ' NERDComment'
2791
+ let target = " '" . a: target . " '"
2792
+ endif
2793
+ let plug_start = ' noremap <silent> ' . plug . ' :call ' . func_name . ' ("'
2794
+ let plug_end = ' ", "' . target . ' ")<cr>'
2755
2795
" Build up a menu command like
2756
2796
" 'menu <silent> comment.Comment<Tab>\\cc <plug>NERDCommenterComment'
2757
2797
let menuRoot = get ([' ' , ' comment' , ' &comment' , ' &Plugin.&comment' ],
0 commit comments