diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 005ee02..eff63d1 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Mon Dec 12 10:00 AM 2011 EST +" Last Change: Mon Dec 12 11:00 AM 2011 EST " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -1016,16 +1016,16 @@ function s:InvertComment(firstLine, lastLine) endwhile endfunction -" Function: NERDComment(isVisual, type) function {{{2 +" Function: s:NERDComment(mode, type) function {{{2 " This function is a Wrapper for the main commenting functions " " Args: -" -isVisual: a flag indicating whether the comment is requested in visual -" mode or not -" -type: the type of commenting requested. Can be 'sexy', 'invert', -" 'minimal', 'toggle', 'alignLeft', 'alignBoth', 'norm', -" 'nested', 'toEOL', 'append', 'insert', 'uncomment', 'yank' -function! NERDComment(isVisual, type) range +" -mode: a character indicating the mode in which the comment is requested: +" 'n' for Normal mode, 'v' for Visual mode +" -type: the type of commenting requested. Can be 'Sexy', 'Invert', +" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Norm', +" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank' +function! s:NERDComment(mode, type) range " we want case sensitivity when commenting let oldIgnoreCase = &ignorecase set noignorecase @@ -1034,7 +1034,7 @@ function! NERDComment(isVisual, type) range call s:NerdEcho("filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on", 0) endif - if a:isVisual + if a:mode == "v" let firstLine = line("'<") let lastLine = line("'>") let firstCol = col("'<") @@ -1044,32 +1044,32 @@ function! NERDComment(isVisual, type) range let lastLine = a:lastline endif - let countWasGiven = (a:isVisual == 0 && firstLine != lastLine) + let countWasGiven = (a:mode != "v" && firstLine != lastLine) - let forceNested = (a:type == 'nested' || g:NERDDefaultNesting) + let forceNested = (a:type == 'Nested' || g:NERDDefaultNesting) - if a:type == 'norm' || a:type == 'nested' - if a:isVisual && visualmode() == "\" + if a:type == 'Norm' || a:type == 'Nested' + if a:mode == "v" && visualmode() == "\" call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) - elseif a:isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) + elseif a:mode == "v" && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested) else call s:CommentLines(forceNested, "none", firstLine, lastLine) endif - elseif a:type == 'alignLeft' || a:type == 'alignBoth' + elseif a:type == 'AlignLeft' || a:type == 'AlignBoth' let align = "none" - if a:type == "alignLeft" + if a:type == "AlignLeft" let align = "left" - elseif a:type == "alignBoth" + elseif a:type == "AlignBoth" let align = "both" endif call s:CommentLines(forceNested, align, firstLine, lastLine) - elseif a:type == 'invert' + elseif a:type == 'Invert' call s:InvertComment(firstLine, lastLine) - elseif a:type == 'sexy' + elseif a:type == 'Sexy' try call s:CommentLinesSexy(firstLine, lastLine) catch /NERDCommenter.Delimiters/ @@ -1078,7 +1078,7 @@ function! NERDComment(isVisual, type) range call s:NerdEcho("Sexy comment aborted. Nested sexy cannot be nested", 0) endtry - elseif a:type == 'toggle' + elseif a:type == 'Toggle' let theLine = getline(firstLine) if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) @@ -1087,7 +1087,7 @@ function! NERDComment(isVisual, type) range call s:CommentLinesToggle(forceNested, firstLine, lastLine) endif - elseif a:type == 'minimal' + elseif a:type == 'Minimal' try call s:CommentLinesMinimal(firstLine, lastLine) catch /NERDCommenter.Delimiters/ @@ -1096,29 +1096,29 @@ function! NERDComment(isVisual, type) range call s:NerdEcho("Place holders are required but disabled.", 0) endtry - elseif a:type == 'toEOL' + elseif a:type == 'ToEOL' call s:SaveScreenState() call s:CommentBlock(firstLine, firstLine, col("."), col("$")-1, 1) call s:RestoreScreenState() - elseif a:type == 'append' + elseif a:type == 'Append' call s:AppendCommentToLine() - elseif a:type == 'insert' + elseif a:type == 'Insert' call s:PlaceDelimitersAndInsBetween() - elseif a:type == 'uncomment' + elseif a:type == 'Uncomment' call s:UncommentLines(firstLine, lastLine) - elseif a:type == 'yank' - if a:isVisual + elseif a:type == 'Yank' + if a:mode == "v" normal! gvy elseif countWasGiven execute firstLine .','. lastLine .'yank' else normal! yy endif - execute firstLine .','. lastLine .'call NERDComment('. a:isVisual .', "norm")' + execute firstLine .','. lastLine .'call s:NERDComment('. a:mode .', "Norm")' endif let &ignorecase = oldIgnoreCase @@ -2694,53 +2694,53 @@ endfunction nnoremap NERDCommenterAltDelims :call SwitchToAlternativeDelimiters(1) " comment out lines -nnoremap NERDCommenterComment :call NERDComment(0, "norm") -vnoremap NERDCommenterComment :call NERDComment(1, "norm") +nnoremap NERDCommenterComment :call NERDComment("n", "Norm") +vnoremap NERDCommenterComment :call NERDComment("v", "Norm") " toggle comments -nnoremap NERDCommenterToggle :call NERDComment(0, "toggle") -vnoremap NERDCommenterToggle :call NERDComment(1, "toggle") +nnoremap NERDCommenterToggle :call NERDComment("n", "Toggle") +vnoremap NERDCommenterToggle :call NERDComment("v", "Toggle") " minimal comments -nnoremap NERDCommenterMinimal :call NERDComment(0, "minimal") -vnoremap NERDCommenterMinimal :call NERDComment(1, "minimal") +nnoremap NERDCommenterMinimal :call NERDComment("n", "Minimal") +vnoremap NERDCommenterMinimal :call NERDComment("v", "Minimal") " sexy comments -nnoremap NERDCommenterSexy :call NERDComment(0, "sexy") -vnoremap NERDCommenterSexy :call NERDComment(1, "sexy") +nnoremap NERDCommenterSexy :call NERDComment("n", "Sexy") +vnoremap NERDCommenterSexy :call NERDComment("v", "Sexy") " invert comments -nnoremap NERDCommenterInvert :call NERDComment(0, "invert") -vnoremap NERDCommenterInvert :call NERDComment(1, "invert") +nnoremap NERDCommenterInvert :call NERDComment("n", "Invert") +vnoremap NERDCommenterInvert :call NERDComment("v", "Invert") " yank then comment -nmap NERDCommenterYank :call NERDComment(0, "yank") -vmap NERDCommenterYank :call NERDComment(1, "yank") +nmap NERDCommenterYank :call NERDComment("n", "Yank") +vmap NERDCommenterYank :call NERDComment("v", "Yank") " left aligned comments -nnoremap NERDCommenterAlignLeft :call NERDComment(0, "alignLeft") -vnoremap NERDCommenterAlignLeft :call NERDComment(1, "alignLeft") +nnoremap NERDCommenterAlignLeft :call NERDComment("n", "AlignLeft") +vnoremap NERDCommenterAlignLeft :call NERDComment("v", "AlignLeft") " left and right aligned comments -nnoremap NERDCommenterAlignBoth :call NERDComment(0, "alignBoth") -vnoremap NERDCommenterAlignBoth :call NERDComment(1, "alignBoth") +nnoremap NERDCommenterAlignBoth :call NERDComment("n", "AlignBoth") +vnoremap NERDCommenterAlignBoth :call NERDComment("v", "AlignBoth") " nested comments -nnoremap NERDCommenterNest :call NERDComment(0, "nested") -vnoremap NERDCommenterNest :call NERDComment(1, "nested") +nnoremap NERDCommenterNest :call NERDComment("n", "Nested") +vnoremap NERDCommenterNest :call NERDComment("v", "Nested") " uncomment -nnoremap NERDCommenterUncomment :call NERDComment(0, "uncomment") -vnoremap NERDCommenterUncomment :call NERDComment(1, "uncomment") +nnoremap NERDCommenterUncomment :call NERDComment("n", "Uncomment") +vnoremap NERDCommenterUncomment :call NERDComment("v", "Uncomment") " comment till the end of the line -nnoremap NERDCommenterToEOL :call NERDComment(0, "toEOL") +nnoremap NERDCommenterToEOL :call NERDComment("n", "ToEOL") " append comments -nmap NERDCommenterAppend :call NERDComment(0, "append") +nmap NERDCommenterAppend :call NERDComment("n", "Append") " insert comments -inoremap NERDCommenterInInsert :call NERDComment(0, "insert") +inoremap NERDCommenterInsert :call NERDComment("n", "Insert") " Section: Menu item setup {{{1 " =========================================================================== @@ -2782,7 +2782,7 @@ call s:CreateMaps('nx', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb call s:CreateMaps('', ':', '-Sep2-', '') call s:CreateMaps('nx', 'NERDCommenterUncomment', 'Uncomment', 'cu') call s:CreateMaps('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') -call s:CreateMaps('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') +call s:CreateMaps('i', 'NERDCommenterInsert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " vim: set foldmethod=marker :