diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index c5805fc..a844474 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -14,7 +14,7 @@ " ============================================================================ " Section: script init stuff {{{1 -if exists("loaded_nerd_comments") +if exists('loaded_nerd_comments') finish endif if v:version < 700 @@ -49,24 +49,24 @@ let s:spaceStr = ' ' let s:lenSpaceStr = strlen(s:spaceStr) " Section: variable initialization {{{2 -call s:InitVariable("g:NERDAllowAnyVisualDelims", 1) -call s:InitVariable("g:NERDBlockComIgnoreEmpty", 0) -call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0) -call s:InitVariable("g:NERDCommentEmptyLines", 0) -call s:InitVariable("g:NERDCompactSexyComs", 0) -call s:InitVariable("g:NERDCreateDefaultMappings", 1) -call s:InitVariable("g:NERDDefaultNesting", 1) -call s:InitVariable("g:NERDMenuMode", 3) -call s:InitVariable("g:NERDLPlace", "[>") -call s:InitVariable("g:NERDUsePlaceHolders", 1) -call s:InitVariable("g:NERDRemoveAltComs", 1) -call s:InitVariable("g:NERDRemoveExtraSpaces", 0) -call s:InitVariable("g:NERDRPlace", "<]") -call s:InitVariable("g:NERDSpaceDelims", 0) -call s:InitVariable("g:NERDDefaultAlign", "none") -call s:InitVariable("g:NERDTrimTrailingWhitespace", 0) -call s:InitVariable("g:NERDToggleCheckAllLines", 0) -call s:InitVariable("g:NERDDisableTabsInBlockComm", 0) +call s:InitVariable('g:NERDAllowAnyVisualDelims', 1) +call s:InitVariable('g:NERDBlockComIgnoreEmpty', 0) +call s:InitVariable('g:NERDCommentWholeLinesInVMode', 0) +call s:InitVariable('g:NERDCommentEmptyLines', 0) +call s:InitVariable('g:NERDCompactSexyComs', 0) +call s:InitVariable('g:NERDCreateDefaultMappings', 1) +call s:InitVariable('g:NERDDefaultNesting', 1) +call s:InitVariable('g:NERDMenuMode', 3) +call s:InitVariable('g:NERDLPlace', '[>') +call s:InitVariable('g:NERDUsePlaceHolders', 1) +call s:InitVariable('g:NERDRemoveAltComs', 1) +call s:InitVariable('g:NERDRemoveExtraSpaces', 0) +call s:InitVariable('g:NERDRPlace', '<]') +call s:InitVariable('g:NERDSpaceDelims', 0) +call s:InitVariable('g:NERDDefaultAlign', 'none') +call s:InitVariable('g:NERDTrimTrailingWhitespace', 0) +call s:InitVariable('g:NERDToggleCheckAllLines', 0) +call s:InitVariable('g:NERDDisableTabsInBlockComm', 0) let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" @@ -320,7 +320,7 @@ let s:delimiterMap = { \ 'omnimark': { 'left': ';' }, \ 'ooc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'openroad': { 'left': '//' }, - \ 'opl': { 'left': "REM" }, + \ 'opl': { 'left': 'REM' }, \ 'ora': { 'left': '#' }, \ 'ox': { 'left': '//' }, \ 'paludis-use-conf': { 'left': '#' }, @@ -442,14 +442,14 @@ let s:delimiterMap = { \ 'teak': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'terraform': { 'left': '#', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'tex': { 'left': '%' }, - \ 'texinfo': { 'left': "@c " }, + \ 'texinfo': { 'left': '@c ' }, \ 'texmf': { 'left': '%' }, \ 'tf': { 'left': '#' }, \ 'tidy': { 'left': '#' }, \ 'tli': { 'left': '#' }, \ 'tmux': { 'left': '#' }, \ 'toml': { 'left': '#' }, - \ 'trasys': { 'left': "$" }, + \ 'trasys': { 'left': '$' }, \ 'troff': { 'left': '.\\"' }, \ 'tsalt': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'tsscl': { 'left': '#' }, @@ -466,7 +466,7 @@ let s:delimiterMap = { \ 'vala': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'vasp': { 'left': '!' }, \ 'vb': { 'left': "'" }, - \ 'velocity': { 'left': "##", 'right': "", 'leftAlt': '#*', 'rightAlt': '*#' }, + \ 'velocity': { 'left': '##', 'right': '', 'leftAlt': '#*', 'rightAlt': '*#' }, \ 'vera': { 'left': '/*', 'right': '*/', 'leftAlt': '//' }, \ 'verilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'verilog_systemverilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, @@ -493,7 +493,7 @@ let s:delimiterMap = { let g:NERDDelimiterMap = s:delimiterMap -if exists("g:NERDCustomDelimiters") +if exists('g:NERDCustomDelimiters') call extend(s:delimiterMap, g:NERDCustomDelimiters) endif @@ -524,15 +524,15 @@ augroup END " set for this buffer. " function s:SetUpForNewFiletype(filetype, forceReset) - let ft = a:filetype + let filetype = a:filetype "for compound filetypes, if we don't know how to handle the full filetype "then break it down and use the first part that we know how to handle - if ft =~ '\.' && !has_key(s:delimiterMap, ft) + if filetype =~# '\.' && !has_key(s:delimiterMap, filetype) let filetypes = split(a:filetype, '\.') for i in filetypes if has_key(s:delimiterMap, i) - let ft = i + let filetype = i break endif endfor @@ -540,8 +540,8 @@ function s:SetUpForNewFiletype(filetype, forceReset) let b:NERDSexyComMarker = '' - if has_key(s:delimiterMap, ft) - let b:NERDCommenterDelims = s:delimiterMap[ft] + if has_key(s:delimiterMap, filetype) + let b:NERDCommenterDelims = s:delimiterMap[filetype] for i in ['left', 'leftAlt', 'right', 'rightAlt'] if !has_key(b:NERDCommenterDelims, i) let b:NERDCommenterDelims[i] = '' @@ -553,8 +553,8 @@ function s:SetUpForNewFiletype(filetype, forceReset) endif endfor " if g:NERD__alt_style is defined, use the alternate style - let b:NERDCommenterFirstInit = getbufvar(1,"NERDCommenterFirstInit") - if exists('g:NERDAltDelims_'.ft) && eval('g:NERDAltDelims_'.ft) && !b:NERDCommenterFirstInit + let b:NERDCommenterFirstInit = getbufvar(1,'NERDCommenterFirstInit') + if exists('g:NERDAltDelims_'.filetype) && eval('g:NERDAltDelims_'.filetype) && !b:NERDCommenterFirstInit call s:SwitchToAlternativeDelimiters(0) let b:NERDCommenterFirstInit = 1 endif @@ -565,7 +565,7 @@ function s:SetUpForNewFiletype(filetype, forceReset) endfunction function s:CreateDelimMapFromCms() - if &ft == '' && exists('g:NERDDefaultDelims') + if &filetype ==# '' && exists('g:NERDDefaultDelims') let delims = g:NERDDefaultDelims for i in ['left', 'leftAlt', 'right', 'rightAlt'] if !has_key(delims, i) @@ -594,13 +594,13 @@ endfunction " if this function changed the delimiters or not function s:SwitchToAlternativeDelimiters(printMsgs) if exists('*NERDCommenter_before') - exe "call NERDCommenter_before()" + exe 'call NERDCommenter_before()' endif "if both of the alternative delimiters are empty then there is no "alternative comment style so bail out - if b:NERDCommenterDelims['leftAlt'] == '' && b:NERDCommenterDelims['rightAlt'] == '' + if b:NERDCommenterDelims['leftAlt'] ==# '' && b:NERDCommenterDelims['rightAlt'] ==# '' if a:printMsgs - call s:NerdEcho("Cannot use alternative delimiters, none are specified", 0) + call s:NerdEcho('Cannot use alternative delimiters, none are specified', 0) endif return 0 endif @@ -623,11 +623,11 @@ function s:SwitchToAlternativeDelimiters(printMsgs) "tell the user what comment delimiters they are now using if a:printMsgs - call s:NerdEcho("Now using " . s:Left() . " " . s:Right() . " to delimit comments", 1) + call s:NerdEcho('Now using ' . s:Left() . ' ' . s:Right() . ' to delimit comments', 1) endif if exists('*NERDCommenter_after') - exe "call NERDCommenter_after()" + exe 'call NERDCommenter_after()' endif return 1 @@ -645,18 +645,18 @@ function s:AppendCommentToLine() " get the length of the right delimiter let lenRight = strlen(right) - let isLineEmpty = strlen(getline(".")) == 0 - let insOrApp = (isLineEmpty==1 ? 'i' : 'A') + let isLineEmpty = strlen(getline('.')) ==# 0 + let insOrApp = (isLineEmpty==#1 ? 'i' : 'A') "stick the delimiters down at the end of the line. We have to format the "comment with spaces as appropriate - execute ":normal! " . insOrApp . (isLineEmpty ? '' : ' ') . left . right + execute ':normal! ' . insOrApp . (isLineEmpty ? '' : ' ') . left . right " if there is a right delimiter then we gotta move the cursor left " by the length of the right delimiter so we insert between the delimiters if lenRight > 0 let leftMoveAmount = lenRight - 1 - execute ":normal! " . leftMoveAmount . "h" + execute ':normal! ' . leftMoveAmount . 'h' startinsert else startinsert! @@ -690,15 +690,15 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) "boundary accordingly let numTabs = s:NumberOfLeadingTabs(topline) if lSide < numTabs - let lSide = &ts * lSide + let lSide = &tabstop * lSide else - let lSide = (lSide - numTabs) + (&ts * numTabs) + let lSide = (lSide - numTabs) + (&tabstop * numTabs) endif "find out how many tabs are in the bottom line and adjust the right "boundary accordingly let numTabs = s:NumberOfLeadingTabs(bottomline) - let rSide = (rSide - numTabs) + (&ts * numTabs) + let rSide = (rSide - numTabs) + (&tabstop * numTabs) endif "we must check that bottom IS actually below top, if it is not then we @@ -740,7 +740,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) "don't comment lines that begin after the right boundary of the "block unless the user has specified to do so - if theLine !~ '^ \{' . rSide . '\}' || !g:NERDBlockComIgnoreEmpty + if theLine !~# '^ \{' . rSide . '\}' || !g:NERDBlockComIgnoreEmpty "attempt to place the cursor in on the left of the boundary box, "then check if we were successful, if not then we cant comment this @@ -761,7 +761,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) let firstLeftDelim = s:FindDelimiterIndex(s:Left(), theLine) let lastRightDelim = s:LastIndexOfDelim(s:Right(), theLine) - if firstLeftDelim != -1 && lastRightDelim != -1 + if firstLeftDelim !=# -1 && lastRightDelim !=# -1 let searchStr = strpart(theLine, 0, lastRightDelim) let searchStr = strpart(searchStr, firstLeftDelim+strlen(s:Left())) @@ -781,7 +781,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -792,7 +792,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) endwhile "if we switched delimiterss then we gotta go back to what they were before - if switchedDelims == 1 + if switchedDelims ==# 1 call s:SwitchToAlternativeDelimiters(0) endif endfunction @@ -809,7 +809,7 @@ function s:CommentLines(forceNested, align, firstLine, lastLine) " we need to get the left and right indexes of the leftmost char in the " block of of lines and the right most char so that we can do alignment of " the delimiters if the user has specified - let leftAlignIndx = a:align == "start" ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) + let leftAlignIndx = a:align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) " gotta add the length of the left delimiter onto the rightAlignIndx cos @@ -837,12 +837,12 @@ function s:CommentLines(forceNested, align, firstLine, lastLine) " check if we can comment this line if !isCommented || g:NERDUsePlaceHolders || s:Multipart() - if a:align == "left" || a:align == "start" || a:align == "both" + if a:align ==# 'left' || a:align ==# 'start' || a:align ==# 'both' let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx) else let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) endif - if a:align == "both" + if a:align ==# 'both' let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx) else let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine) @@ -855,7 +855,7 @@ function s:CommentLines(forceNested, align, firstLine, lastLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -920,7 +920,7 @@ function s:CommentLinesMinimal(firstLine, lastLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -940,7 +940,7 @@ function s:CommentLinesSexy(topline, bottomline) let right = s:GetSexyComRight(0, 0) "check if we can do a sexy comment with the available delimiters - if left == -1 || right == -1 + if left ==# -1 || right ==# -1 throw 'NERDCommenter.Delimiters exception: cannot perform sexy comments with available delimiters.' endif @@ -979,7 +979,7 @@ function s:CommentLinesSexy(topline, bottomline) call setline(a:topline, theLine) "comment the bottom line - if a:bottomline != a:topline + if a:bottomline !=# a:topline let theLine = getline(a:bottomline) let lineHasTabs = s:HasLeadingTabs(theLine) if lineHasTabs @@ -1051,7 +1051,7 @@ function s:CommentLinesSexy(topline, bottomline) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -1073,7 +1073,7 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine) let currentLine = a:firstLine let align = g:NERDDefaultAlign - let leftAlignIndx = align == "start" ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) + let leftAlignIndx = align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let rightAlignIndx = rightAlignIndx + strlen(s:Left({'space': 1})) @@ -1091,12 +1091,12 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine) let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine) endif - if align == 'left' || align == 'start' || align == 'both' + if align ==# 'left' || align ==# 'start' || align ==# 'both' let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx) else let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) endif - if align == "both" + if align ==# 'both' let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx) else let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine) @@ -1108,7 +1108,7 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -1139,7 +1139,7 @@ function s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) endif "if there is only one line in the comment then just do it - if a:topLine == a:bottomLine + if a:topLine ==# a:bottomLine call s:CommentBlock(a:topLine, a:bottomLine, a:topCol, a:bottomCol, a:forceNested) "there are multiple lines in the comment @@ -1165,7 +1165,7 @@ function s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) call cursor(a:topLine, a:topCol + strlen(s:Left()) + g:NERDSpaceDelims) "if we switched delimiters then we gotta go back to what they were before - if switchedDelims == 1 + if switchedDelims ==# 1 call s:SwitchToAlternativeDelimiters(0) endif @@ -1225,20 +1225,20 @@ endfunction " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank' function! NERDComment(mode, type) range if exists('*NERDCommenter_before') - exe "call NERDCommenter_before()" + exe 'call NERDCommenter_before()' endif - let isVisual = a:mode =~ '[vsx]' + let isVisual = a:mode =~# '[vsx]' - if !exists("g:did_load_ftplugin") || g:did_load_ftplugin != 1 - call s:NerdEcho("filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on", 0) + if !exists('g:did_load_ftplugin') || g:did_load_ftplugin !=# 1 + call s:NerdEcho('filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on', 0) endif if isVisual let firstLine = line("'<") let lastLine = line("'>") let firstCol = col("'<") - let lastCol = col("'>") - (&selection == 'exclusive' ? 1 : 0) + let lastCol = col("'>") - (&selection ==# 'exclusive' ? 1 : 0) else let firstLine = a:firstline let lastLine = a:lastline @@ -1247,25 +1247,25 @@ function! NERDComment(mode, type) range " Save options we need to change so we can recover them later let state = s:SetupStateBeforeLineComment(firstLine, lastLine) - let countWasGiven = (!isVisual && firstLine != lastLine) + let countWasGiven = (!isVisual && firstLine !=# lastLine) let forceNested = (a:type ==? 'Nested' || g:NERDDefaultNesting) if a:type ==? 'Comment' || a:type ==? 'Nested' - if isVisual && visualmode() == "\" + if isVisual && visualmode() ==# "\" call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) - elseif isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) + elseif isVisual && visualmode() ==# 'v' && (g:NERDCommentWholeLinesInVMode==#0 || (g:NERDCommentWholeLinesInVMode==#2 && s:HasMultipartDelims())) call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested) else call s:CommentLines(forceNested, g:NERDDefaultAlign, firstLine, lastLine) endif elseif a:type ==? 'AlignLeft' || a:type ==? 'AlignBoth' - let align = "none" - if a:type ==? "AlignLeft" - let align = "left" - elseif a:type ==? "AlignBoth" - let align = "both" + let align = 'none' + if a:type ==? 'AlignLeft' + let align = 'left' + elseif a:type ==? 'AlignBoth' + let align = 'both' endif call s:CommentLines(forceNested, align, firstLine, lastLine) @@ -1278,7 +1278,7 @@ function! NERDComment(mode, type) range catch /NERDCommenter.Delimiters/ call s:CommentLines(forceNested, g:NERDDefaultAlign, firstLine, lastLine) catch /NERDCommenter.Nesting/ - call s:NerdEcho("Sexy comment aborted. Nested sexy cannot be nested", 0) + call s:NerdEcho('Sexy comment aborted. Nested sexy cannot be nested', 0) endtry elseif a:type ==? 'Toggle' @@ -1294,7 +1294,7 @@ function! NERDComment(mode, type) range for i in range(firstLine, lastLine) let theLine = getline(i) " if have one line no comment(not include blank/whitespace-only lines), then comment all lines - if theLine =~ '[^ \t]\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) + if theLine =~# '[^ \t]\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) let l:commentAllLines = 1 break else @@ -1311,14 +1311,14 @@ function! NERDComment(mode, type) range try call s:CommentLinesMinimal(firstLine, lastLine) catch /NERDCommenter.Delimiters/ - call s:NerdEcho("Minimal comments can only be used for filetypes that have multipart delimiters.", 0) + call s:NerdEcho('Minimal comments can only be used for filetypes that have multipart delimiters.', 0) catch /NERDCommenter.Settings/ - call s:NerdEcho("Place holders are required but disabled.", 0) + call s:NerdEcho('Place holders are required but disabled.', 0) endtry elseif a:type ==? 'ToEOL' call s:SaveScreenState() - call s:CommentBlock(firstLine, firstLine, col("."), col("$")-1, 1) + call s:CommentBlock(firstLine, firstLine, col('.'), col('$')-1, 1) call s:RestoreScreenState() elseif a:type ==? 'Append' @@ -1345,13 +1345,13 @@ function! NERDComment(mode, type) range if isVisual let nlines = lastLine - firstLine - silent! call repeat#set("V" . nlines . "jo" . "\NERDCommenter". a:type) + silent! call repeat#set('V' . nlines . 'jo' . "\NERDCommenter". a:type) else silent! call repeat#set("\NERDCommenter". a:type) endif if exists('*NERDCommenter_after') - exe "call NERDCommenter_after()" + exe 'call NERDCommenter_after()' endif endfunction @@ -1364,43 +1364,43 @@ function s:PlaceDelimitersAndInsBetween() let left = s:Left({'space': 1}) let right = s:Right({'space': 1}) - let theLine = getline(".") - let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~ '^ *$' && !&expandtab) + let theLine = getline('.') + let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~# '^ *$' && !&expandtab) "convert tabs to spaces and adjust the cursors column to take this into "account - let untabbedCol = s:UntabbedCol(theLine, col(".")) - call setline(line("."), s:ConvertLeadingTabsToSpaces(theLine)) - call cursor(line("."), untabbedCol) + let untabbedCol = s:UntabbedCol(theLine, col('.')) + call setline(line('.'), s:ConvertLeadingTabsToSpaces(theLine)) + call cursor(line('.'), untabbedCol) " get the length of the right delimiter let lenRight = strlen(right) - let isDelimOnEOL = col(".") >= strlen(getline(".")) + let isDelimOnEOL = col('.') >= strlen(getline('.')) " if the cursor is in the first col then we gotta insert rather than " append the comment delimiters here - let insOrApp = (col(".")==1 ? 'i' : 'a') + let insOrApp = (col('.')==1 ? 'i' : 'a') " place the delimiters down. We do it differently depending on whether " there is a left AND right delimiter if lenRight > 0 - execute ":normal! " . insOrApp . left . right - execute ":normal! " . lenRight . "h" + execute ':normal! ' . insOrApp . left . right + execute ':normal! ' . lenRight . 'h' else - execute ":normal! " . insOrApp . left + execute ':normal! ' . insOrApp . left endif silent! normal! l "if needed convert spaces back to tabs and adjust the cursors col "accordingly if lineHasLeadTabs - let tabbedCol = s:TabbedCol(getline("."), col(".")) - call setline(line("."), s:ConvertLeadingSpacesToTabs(getline("."))) - call cursor(line("."), tabbedCol) + let tabbedCol = s:TabbedCol(getline('.'), col('.')) + call setline(line('.'), s:ConvertLeadingSpacesToTabs(getline('.'))) + call cursor(line('.'), tabbedCol) endif - if isDelimOnEOL && lenRight == 0 + if isDelimOnEOL && lenRight ==# 0 startinsert! else startinsert @@ -1412,7 +1412,7 @@ endfunction " last right delimiter of the given line. " " The arguments left and right must be strings. If there is no right delimiter (as -" is the case for e.g vim file comments) them the argument right should be "" +" is the case for e.g vim file comments) them the argument right should be '' " " Args: " -left: the left comment delimiter @@ -1431,24 +1431,24 @@ function s:RemoveDelimiters(left, right, line) "look for the left delimiter, if we find it, remove it. let leftIndx = s:FindDelimiterIndex(a:left, line) - if leftIndx != -1 + if leftIndx !=# -1 let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+lenLeft) "if the user has specified that there is a space after the left delimiter "then check for the space and remove it if it is there - if delimsSpaced && strpart(line, leftIndx, s:lenSpaceStr) == s:spaceStr + if delimsSpaced && strpart(line, leftIndx, s:lenSpaceStr) ==# s:spaceStr let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+s:lenSpaceStr) endif endif "look for the right delimiter, if we find it, remove it let rightIndx = s:LastIndexOfDelim(a:right, line) - if rightIndx != -1 + if rightIndx !=# -1 let line = strpart(line, 0, rightIndx) . strpart(line, rightIndx+lenRight) "if the user has specified that there is a space before the right delimiter "then check for the space and remove it if it is there - if delimsSpaced && strpart(line, rightIndx-s:lenSpaceStr, s:lenSpaceStr) == s:spaceStr && (s:Multipart() || s:AltMultipart()) + if delimsSpaced && strpart(line, rightIndx-s:lenSpaceStr, s:lenSpaceStr) ==# s:spaceStr && (s:Multipart() || s:AltMultipart()) let line = strpart(line, 0, rightIndx-s:lenSpaceStr) . strpart(line, rightIndx) endif endif @@ -1475,7 +1475,7 @@ function s:SetupStateBeforeLineComment(topLine, bottomLine) " manual, do the commenting stuff and recover it later. To avoid slowing " down commenting few lines, we avoid doing this for ranges smaller than " 10 lines - if a:bottomLine - a:topLine >= 10 && &foldmethod != "manual" + if a:bottomLine - a:topLine >= 10 && &foldmethod !=# 'manual' set foldmethod=manual endif @@ -1493,10 +1493,10 @@ endfunction " state: the top line of the visual selection to uncomment " bottomLine: the bottom line of the visual selection to uncomment function s:RecoverStateAfterLineComment(state) - if a:state['foldmethod'] != &foldmethod + if a:state['foldmethod'] !=# &foldmethod let &foldmethod = a:state['foldmethod'] endif - if a:state['ignorecase'] != &ignorecase + if a:state['ignorecase'] !=# &ignorecase let &ignorecase = a:state['ignorecase'] endif endfunction @@ -1568,7 +1568,7 @@ function s:UncommentLinesSexy(topline, bottomline) "check if it is even possible for sexy comments to exist with the "available delimiters - if left == -1 || right == -1 + if left ==# -1 || right ==# -1 throw 'NERDCommenter.Delimiters exception: cannot uncomment sexy comments with available delimiters.' endif @@ -1592,7 +1592,7 @@ function s:UncommentLinesSexy(topline, bottomline) " remove the sexy comment marker from the line. We also remove the " space after it if there is one and if appropriate options are set let sexyComMarkerIndx = stridx(theLine, sexyComMarkerUnEsc) - if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims + if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)+s:lenSpaceStr) else let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)) @@ -1602,7 +1602,7 @@ function s:UncommentLinesSexy(topline, bottomline) let theLine = s:ConvertLeadingWhiteSpace(theLine) - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -1619,7 +1619,7 @@ function s:UncommentLinesSexy(topline, bottomline) let theLine = getline(a:topline) " if the first line contains only the left delimiter then just delete it - if theLine =~ '^[ \t]*' . left . '[ \t]*$' && !g:NERDCompactSexyComs + if theLine =~# '^[ \t]*' . left . '[ \t]*$' && !g:NERDCompactSexyComs call cursor(a:topline, 1) normal! dd let bottomline = bottomline - 1 @@ -1630,7 +1630,7 @@ function s:UncommentLinesSexy(topline, bottomline) " remove the delimiter. If there is a space after it " then remove this too if appropriate let delimIndx = stridx(theLine, leftUnEsc) - if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims + if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc)+s:lenSpaceStr) else let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc)) @@ -1643,7 +1643,7 @@ function s:UncommentLinesSexy(topline, bottomline) let theLine = getline(bottomline) " if the bottomline contains only the right delimiter then just delete it - if theLine =~ '^[ \t]*' . right . '[ \t]*$' + if theLine =~# '^[ \t]*' . right . '[ \t]*$' call cursor(bottomline, 1) normal! dd @@ -1652,7 +1652,7 @@ function s:UncommentLinesSexy(topline, bottomline) " remove the right delimiter. If there is a space after it and " if the appropriate options are set then remove this too. let delimIndx = s:LastIndexOfDelim(rightUnEsc, theLine) - if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims + if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(rightUnEsc)+s:lenSpaceStr) else let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(rightUnEsc)) @@ -1660,12 +1660,12 @@ function s:UncommentLinesSexy(topline, bottomline) " if the last line also starts with a sexy comment marker then we " remove this as well - if theLine =~ '^[ \t]*' . sexyComMarker + if theLine =~# '^[ \t]*' . sexyComMarker " remove the sexyComMarker. If there is a space after it then " remove that too let sexyComMarkerIndx = stridx(theLine, sexyComMarkerUnEsc) - if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims + if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)+s:lenSpaceStr) else let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)) @@ -1677,7 +1677,7 @@ function s:UncommentLinesSexy(topline, bottomline) endif " remove trailing whitespaces for first and last line - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = getline(a:bottomline) let theLine = s:TrimTrailingWhitespace(theLine) call setline(a:bottomline, theLine) @@ -1704,27 +1704,27 @@ function s:UncommentLineNormal(line) let lineCommentStatus = s:IsCommentedOutermost(s:Left(), s:Right(), s:Left({'alt': 1}), s:Right({'alt': 1}), line) "it is commented with s:Left() and s:Right() so remove these delimiters - if lineCommentStatus == 1 + if lineCommentStatus ==# 1 let line = s:RemoveDelimiters(s:Left(), s:Right(), line) "it is commented with s:Left({'alt': 1}) and s:Right({'alt': 1}) so remove these delimiters - elseif lineCommentStatus == 2 && g:NERDRemoveAltComs + elseif lineCommentStatus ==# 2 && g:NERDRemoveAltComs let line = s:RemoveDelimiters(s:Left({'alt': 1}), s:Right({'alt': 1}), line) "it is not properly commented with any delimiters so we check if it has "any random left or right delimiters on it and remove the outermost ones else "remove the outer most left comment delimiter - if indxLeft != -1 && (indxLeft < indxLeftAlt || indxLeftAlt == -1) + if indxLeft !=# -1 && (indxLeft < indxLeftAlt || indxLeftAlt ==# -1) let line = s:RemoveDelimiters(s:Left(), '', line) - elseif indxLeftAlt != -1 && g:NERDRemoveAltComs + elseif indxLeftAlt !=# -1 && g:NERDRemoveAltComs let line = s:RemoveDelimiters(s:Left({'alt': 1}), '', line) endif "remove the outer most right comment delimiter - if indxRight != -1 && (indxRight < indxRightAlt || indxRightAlt == -1) + if indxRight !=# -1 && (indxRight < indxRightAlt || indxRightAlt ==# -1) let line = s:RemoveDelimiters('', s:Right(), line) - elseif indxRightAlt != -1 && g:NERDRemoveAltComs + elseif indxRightAlt !=# -1 && g:NERDRemoveAltComs let line = s:RemoveDelimiters('', s:Right({'alt': 1}), line) endif endif @@ -1744,11 +1744,11 @@ function s:UncommentLineNormal(line) "if there are place-holders on the line then we check to see if they are "the outermost delimiters on the line. If so then we replace them with "real delimiters - if indxLeftPlace != -1 + if indxLeftPlace !=# -1 if (indxLeftPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line) endif - elseif indxRightPlace != -1 + elseif indxRightPlace !=# -1 if (indxRightPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line) endif @@ -1757,7 +1757,7 @@ function s:UncommentLineNormal(line) let line = s:ConvertLeadingWhiteSpace(line) - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let line = s:TrimTrailingWhitespace(line) endif @@ -1804,7 +1804,7 @@ endfunction " Function: s:AddRightDelim(delim, theLine) {{{2 " Args: function s:AddRightDelim(delim, theLine) - if a:delim == '' + if a:delim ==# '' return a:theLine else return substitute(a:theLine, '$', a:delim, '') @@ -1814,7 +1814,7 @@ endfunction " Function: s:AddRightDelimAligned(delim, theLine, alignIndx) {{{2 " Args: function s:AddRightDelimAligned(delim, theLine, alignIndx) - if a:delim == "" + if a:delim ==# '' return a:theLine else @@ -1832,7 +1832,7 @@ endfunction " Function: s:AltMultipart() {{{2 " returns 1 if the alternative delimiters are multipart function s:AltMultipart() - return b:NERDCommenterDelims['rightAlt'] != '' + return b:NERDCommenterDelims['rightAlt'] !=# '' endfunction " Function: s:AltNested() {{{2 @@ -1854,7 +1854,7 @@ function s:CanCommentLine(forceNested, lineNum) " make sure we don't comment lines that are just spaces or tabs or empty, " unless configured otherwise - if g:NERDCommentEmptyLines == 0 && theLine =~ "^[ \t]*$" + if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$" return 0 endif @@ -1881,10 +1881,10 @@ endfunction " Function: s:CanPlaceCursor(line, col) {{{2 " returns 1 if the cursor can be placed exactly in the given position function s:CanPlaceCursor(line, col) - let c = col(".") - let l = line(".") + let c = col('.') + let l = line('.') call cursor(a:line, a:col) - let success = (line(".") == a:line && col(".") == a:col) + let success = (line('.') ==# a:line && col('.') ==# a:col) call cursor(l,c) return success endfunction @@ -1921,7 +1921,7 @@ function s:CanToggleCommentLine(forceNested, lineNum) " make sure we don't comment lines that are just spaces or tabs or empty, " unless configured otherwise - if g:NERDCommentEmptyLines == 0 && theLine =~ "^[ \t]*$" + if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$" return 0 endif @@ -1941,8 +1941,8 @@ endfunction " -line: the line whose leading tabs will be converted function s:ConvertLeadingSpacesToTabs(line) let toReturn = a:line - while toReturn =~ '^\t*' . s:TabSpace() . '\(.*\)$' - let toReturn = substitute(toReturn, '^\(\t*\)' . s:TabSpace() . '\(.*\)$' , '\1\t\2' , "") + while toReturn =~# '^\t*' . s:TabSpace() . '\(.*\)$' + let toReturn = substitute(toReturn, '^\(\t*\)' . s:TabSpace() . '\(.*\)$' , '\1\t\2' , '') endwhile return toReturn @@ -1957,22 +1957,22 @@ endfunction " -line: the line whose leading spaces will be converted function s:ConvertLeadingTabsToSpaces(line) let toReturn = a:line - while toReturn =~ '^\( *\)\t' - let toReturn = substitute(toReturn, '^\( *\)\t', '\1' . s:TabSpace() , "") + while toReturn =~# '^\( *\)\t' + let toReturn = substitute(toReturn, '^\( *\)\t', '\1' . s:TabSpace() , '') endwhile return toReturn endfunction " Function: s:ConvertLeadingWhiteSpace(line) {{{2 -" Converts the leading white space to tabs/spaces depending on &ts +" Converts the leading white space to tabs/spaces depending on &tabstop " " Args: " -line: the line to convert function s:ConvertLeadingWhiteSpace(line) let toReturn = a:line - while toReturn =~ '^ *\t' - let toReturn = substitute(toReturn, '^ *\zs\t\ze', s:TabSpace(), "g") + while toReturn =~# '^ *\t' + let toReturn = substitute(toReturn, '^ *\zs\t\ze', s:TabSpace(), 'g') endwhile if !&expandtab @@ -1996,7 +1996,7 @@ function s:CountNonESCedOccurances(str, searchstr, escChar) let indx = stridx(a:str, a:searchstr) "if there is an instance of searchstr in str process it - if indx != -1 + if indx !=# -1 "get the remainder of str after this instance of searchstr is removed let lensearchstr = strlen(a:searchstr) let strLeft = strpart(a:str, indx+lensearchstr) @@ -2020,7 +2020,7 @@ function s:DoesBlockHaveDelim(delim, top, bottom) let currentLine = a:top while currentLine < a:bottom let theline = getline(currentLine) - if s:FindDelimiterIndex(a:delim, theline) != -1 + if s:FindDelimiterIndex(a:delim, theline) !=# -1 return 1 endif let currentLine = currentLine + 1 @@ -2062,7 +2062,7 @@ endfunction function s:FindDelimiterIndex(delimiter, line) "make sure the delimiter isn't empty otherwise we go into an infinite loop. - if a:delimiter == "" + if a:delimiter ==# '' return -1 endif @@ -2075,12 +2075,12 @@ function s:FindDelimiterIndex(delimiter, line) "keep looping thru the line till we either find a real comment delimiter "or run off the EOL - while delIndx != -1 + while delIndx !=# -1 "if we are not off the EOL get the str before the possible delimiter "in question and check if it really is a delimiter. If it is, return "its position - if delIndx != -1 + if delIndx !=# -1 if s:IsDelimValid(l:delimiter, delIndx, a:line) return delIndx endif @@ -2094,7 +2094,7 @@ function s:FindDelimiterIndex(delimiter, line) "if distToNextDelim is -1 then there is no more potential delimiters "on the line so set delIndx to -1. Otherwise, move along the line by "distToNextDelim - if distToNextDelim == -1 + if distToNextDelim ==# -1 let delIndx = -1 else let delIndx = delIndx + lenDel + distToNextDelim @@ -2138,20 +2138,20 @@ function s:FindBoundingLinesOfSexyCom(lineNum) let bottom = -1 let currentLine = a:lineNum - while top == -1 || bottom == -1 + while top ==# -1 || bottom ==# -1 let theLine = getline(currentLine) "check if the current line is the top of the sexy comment - if currentLine <= a:lineNum && theLine =~ '^[ \t]*' . left && theLine !~ '.*' . right && currentLine < s:NumLinesInBuf() + if currentLine <= a:lineNum && theLine =~# '^[ \t]*' . left && theLine !~# '.*' . right && currentLine < s:NumLinesInBuf() let top = currentLine let currentLine = a:lineNum "check if the current line is the bottom of the sexy comment - elseif theLine =~ '^[ \t]*' . right && theLine !~ '.*' . left && currentLine > 1 + elseif theLine =~# '^[ \t]*' . right && theLine !~# '.*' . left && currentLine > 1 let bottom = currentLine "the right delimiter is on the same line as the last sexyComMarker - elseif theLine =~ '^[ \t]*' . sexyComMarker . '.*' . right + elseif theLine =~# '^[ \t]*' . sexyComMarker . '.*' . right let bottom = currentLine "we have not found the top or bottom line so we assume currentLine is an @@ -2160,14 +2160,14 @@ function s:FindBoundingLinesOfSexyCom(lineNum) "if the line doesn't start with a sexyComMarker then it is not a sexy "comment - if theLine !~ '^[ \t]*' . sexyComMarker + if theLine !~# '^[ \t]*' . sexyComMarker return [] endif endif "if top is -1 then we haven't found the top yet so keep looking up - if top == -1 + if top ==# -1 let currentLine = currentLine - 1 "if we have found the top line then go down looking for the bottom else @@ -2195,7 +2195,7 @@ function s:GetSexyComMarker(space, esc) let sexyComMarker = b:NERDSexyComMarker "if there is no hardcoded marker then we find one - if sexyComMarker == '' + if sexyComMarker ==# '' "if the filetype has c style comments then use standard c sexy "comments @@ -2242,7 +2242,7 @@ function s:SexyNested() "assume c style sexy comments if possible if s:HasCStyleComments() - return (s:Left() == '/*' && s:Nested()) || (s:Left({'alt': 1}) == '/*' && s:AltNested()) + return (s:Left() ==# '/*' && s:Nested()) || (s:Left({'alt': 1}) ==# '/*' && s:AltNested()) else "grab the longest left delim that has a right if s:Multipart() && lenLeft >= lenLeftAlt @@ -2340,7 +2340,7 @@ endfunction " Returns 1 if any of the given strings have leading tabs function s:HasLeadingTabs(...) for s in a:000 - if s =~ '^\t.*' + if s =~# '^\t.*' return 1 end endfor @@ -2349,7 +2349,7 @@ endfunction " Function: s:HasCStyleComments() {{{2 " Returns 1 if the current filetype has c style comment delimiters function s:HasCStyleComments() - return (s:Left() == '/*' && s:Right() == '*/') || (s:Left({'alt': 1}) == '/*' && s:Right({'alt': 1}) == '*/') + return (s:Left() ==# '/*' && s:Right() ==# '*/') || (s:Left({'alt': 1}) ==# '/*' && s:Right({'alt': 1}) ==# '*/') endfunction " Function: s:IsCommentedNormOrSexy(lineNum) {{{2 @@ -2382,7 +2382,7 @@ endfunction " -left/right: the left and right delimiters to check for function s:IsCommented(left, right, line) "if the line isn't commented return true - if s:FindDelimiterIndex(a:left, a:line) != -1 && (s:LastIndexOfDelim(a:right, a:line) != -1 || !s:Multipart()) + if s:FindDelimiterIndex(a:left, a:line) !=# -1 && (s:LastIndexOfDelim(a:right, a:line) !=# -1 || !s:Multipart()) return 1 endif return 0 @@ -2400,7 +2400,7 @@ function s:IsCommentedFromStartOfLine(left, line) let theLine = s:ConvertLeadingTabsToSpaces(a:line) let numSpaces = strlen(substitute(theLine, '^\( *\).*$', '\1', '')) let delimIndx = s:FindDelimiterIndex(a:left, theLine) - return delimIndx == numSpaces + return delimIndx ==# numSpaces endfunction " Function: s:IsCommentedOutermost(left, right, leftAlt, rightAlt, line) {{{2 @@ -2425,14 +2425,14 @@ function s:IsCommentedOutermost(left, right, leftAlt, rightAlt, line) let indxRightAlt = s:LastIndexOfDelim(a:rightAlt, a:line) "check if the line has a left delimiter before a leftAlt delimiter - if (indxLeft <= indxLeftAlt || indxLeftAlt == -1) && indxLeft != -1 + if (indxLeft <= indxLeftAlt || indxLeftAlt ==# -1) && indxLeft !=# -1 "check if the line has a right delimiter after any rightAlt delimiter if (indxRight > indxRightAlt && indxRight > indxLeft) || !s:Multipart() return 1 endif "check if the line has a leftAlt delimiter before a left delimiter - elseif (indxLeftAlt <= indxLeft || indxLeft == -1) && indxLeftAlt != -1 + elseif (indxLeftAlt <= indxLeft || indxLeft ==# -1) && indxLeftAlt !=# -1 "check if the line has a rightAlt delimiter after any right delimiter if (indxRightAlt > indxRight && indxRightAlt > indxLeftAlt) || !s:AltMultipart() return 2 @@ -2474,13 +2474,13 @@ function s:IsDelimValid(delimiter, delIndx, line) "to check if the delimiter is real, make sure it isn't preceded by "an odd number of quotes and followed by the same (which would indicate "that it is part of a string and therefore is not a comment) - if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\")) && !s:IsNumEven(s:CountNonESCedOccurances(postComStr, '"', "\\")) + if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\")) && !s:IsNumEven(s:CountNonESCedOccurances(postComStr, '"', '\\')) return 0 endif - if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, "'", "\\")) && !s:IsNumEven(s:CountNonESCedOccurances(postComStr, "'", "\\")) + if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, "'", '\\')) && !s:IsNumEven(s:CountNonESCedOccurances(postComStr, "'", '\\')) return 0 endif - if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, "`", "\\")) && !s:IsNumEven(s:CountNonESCedOccurances(postComStr, "`", "\\")) + if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '`', '\\')) && !s:IsNumEven(s:CountNonESCedOccurances(postComStr, '`', '\\')) return 0 endif @@ -2493,19 +2493,19 @@ function s:IsDelimValid(delimiter, delIndx, line) "vim comments are so fucking stupid!! Why the hell do they have comment "delimiters that are used elsewhere in the syntax?!?! We need to check "some conditions especially for vim - if &filetype == "vim" + if &filetype ==# 'vim' if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\")) return 0 endif "if the delimiter is on the very first char of the line or is the "first non-tab/space char on the line then it is a valid comment delimiter - if a:delIndx == 0 || a:line =~ "^[ \t]\\{" . a:delIndx . "\\}\".*$" + if a:delIndx ==# 0 || a:line =~# "^[ \t]\\{" . a:delIndx . "\\}\".*$" return 1 endif - let numLeftParen =s:CountNonESCedOccurances(preComStr, "(", "\\") - let numRightParen =s:CountNonESCedOccurances(preComStr, ")", "\\") + let numLeftParen =s:CountNonESCedOccurances(preComStr, '(', '\\') + let numRightParen =s:CountNonESCedOccurances(preComStr, ')', '\\') "if the quote is inside brackets then assume it isn't a comment if numLeftParen > numRightParen @@ -2514,7 +2514,7 @@ function s:IsDelimValid(delimiter, delIndx, line) "if the line has an even num of unescaped "'s then we can assume that "any given " is not a comment delimiter - if s:IsNumEven(s:CountNonESCedOccurances(a:line, "\"", "\\")) + if s:IsNumEven(s:CountNonESCedOccurances(a:line, '"', '\\')) return 0 endif endif @@ -2528,7 +2528,7 @@ endfunction " Args: " -num: the number to check function s:IsNumEven(num) - return (a:num % 2) == 0 + return (a:num % 2) ==# 0 endfunction " Function: s:IsEscaped(str, indx, escChar) {{{2 @@ -2546,7 +2546,7 @@ function s:IsEscaped(str, indx, escChar) "keep going back thru str until we either reach the start of the str or "run out of esc chars - while curIndx >= 0 && strpart(a:str, curIndx, 1) == a:escChar + while curIndx >= 0 && strpart(a:str, curIndx, 1) ==# a:escChar "we have found another esc char so add one to the count and move left "one char @@ -2591,8 +2591,8 @@ function s:IsSexyComment(topline, bottomline) let topline = a:topline let bottomline = a:bottomline if bottomline < topline - topline = bottomline - bottomline = a:topline + let topline = bottomline + let bottomline = a:topline endif "if there is < 2 lines in the comment it cannot be sexy @@ -2601,23 +2601,23 @@ function s:IsSexyComment(topline, bottomline) endif "if the top line doesn't begin with a left delimiter then the comment isn't sexy - if getline(a:topline) !~ '^[ \t]*' . left + if getline(a:topline) !~# '^[ \t]*' . left return 0 endif "if there is a right delimiter on the top line then this isn't a sexy comment - if s:LastIndexOfDelim(right, getline(a:topline)) != -1 + if s:LastIndexOfDelim(right, getline(a:topline)) !=# -1 return 0 endif "if there is a left delimiter on the bottom line then this isn't a sexy comment - if s:FindDelimiterIndex(left, getline(a:bottomline)) != -1 + if s:FindDelimiterIndex(left, getline(a:bottomline)) !=# -1 return 0 endif "if the bottom line doesn't begin with a right delimiter then the comment isn't "sexy - if getline(a:bottomline) !~ '^.*' . right . '$' + if getline(a:bottomline) !~# '^.*' . right . '$' return 0 endif @@ -2629,13 +2629,13 @@ function s:IsSexyComment(topline, bottomline) while currentLine < a:bottomline let theLine = getline(currentLine) - if theLine !~ '^[ \t]*' . sexyComMarker + if theLine !~# '^[ \t]*' . sexyComMarker return 0 endif "if there is a right delimiter in an intermediate line then the block isn't "a sexy comment - if s:LastIndexOfDelim(right, theLine) != -1 + if s:LastIndexOfDelim(right, theLine) !=# -1 return 0 endif @@ -2660,7 +2660,7 @@ function s:LastIndexOfDelim(delim, str) "set index to the first occurrence of delimiter. If there is no occurrence then "bail let indx = s:FindDelimiterIndex(delim, a:str) - if indx == -1 + if indx ==# -1 return -1 endif @@ -2674,7 +2674,7 @@ function s:LastIndexOfDelim(delim, str) "if we find a delimiter update indx to record the position of it, if we "don't find another delimiter then indx is the last one so break out of "this loop - if indx2 != -1 + if indx2 !=# -1 let indx = indx + indx2 + lenDelim else break @@ -2692,7 +2692,7 @@ function s:Left(...) let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left'] - if delim == '' + if delim ==# '' return '' endif @@ -2728,7 +2728,7 @@ function s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomlin " get the next line and if it is allowed to be commented, or is not " commented, check it let theLine = getline(currentLine) - if a:countEmptyLines || theLine !~ '^[ \t]*$' + if a:countEmptyLines || theLine !~# '^[ \t]*$' if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine)) " convert spaces to tabs and get the number of leading spaces for " this line and update leftMostIndx if need be @@ -2744,7 +2744,7 @@ function s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomlin let currentLine = currentLine + 1 endwhile - if leftMostIndx == 1000 + if leftMostIndx ==# 1000 return 0 else return leftMostIndx @@ -2754,7 +2754,7 @@ endfunction " Function: s:Multipart() {{{2 " returns 1 if the current delimiters are multipart function s:Multipart() - return s:Right() != '' + return s:Right() !=# '' endfunction " Function: s:NerdEcho(msg, typeOfMsg) {{{2 @@ -2763,11 +2763,11 @@ endfunction " -typeOfMsg: 0 = warning message " 1 = normal message function s:NerdEcho(msg, typeOfMsg) - if a:typeOfMsg == 0 + if a:typeOfMsg ==# 0 echohl WarningMsg echom 'NERDCommenter:' . a:msg echohl None - elseif a:typeOfMsg == 1 + elseif a:typeOfMsg ==# 1 echom 'NERDCommenter:' . a:msg endif endfunction @@ -2781,7 +2781,7 @@ endfunction " Function: s:NumberOfLeadingTabs(s) {{{2 " returns the number of leading tabs in the given string function s:NumberOfLeadingTabs(s) - return strlen(substitute(a:s, '^\(\t*\).*$', '\1', "")) + return strlen(substitute(a:s, '^\(\t*\).*$', '\1', '')) endfunction " Function: s:NumLinesInBuf() {{{2 @@ -2822,7 +2822,7 @@ function s:ReplaceLeftMostDelim(toReplace, replacor, str) "if there IS an occurrence of toReplace in str then replace it and return "the resulting string - if indxToReplace != -1 + if indxToReplace !=# -1 let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace)) return line endif @@ -2849,7 +2849,7 @@ function s:ReplaceRightMostDelim(toReplace, replacor, str) "if there IS a delimiter in str, replace it and return the result let line = a:str - if indxToReplace != -1 + if indxToReplace !=# -1 let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace)) endif return line @@ -2861,13 +2861,13 @@ endfunction "called. " function s:RestoreScreenState() - if !exists("t:NERDComOldTopLine") || !exists("t:NERDComOldPos") + if !exists('t:NERDComOldTopLine') || !exists('t:NERDComOldPos') throw 'NERDCommenter exception: cannot restore screen' endif call cursor(t:NERDComOldTopLine, 0) normal! zt - call setpos(".", t:NERDComOldPos) + call setpos('.', t:NERDComOldPos) endfunction " Function: s:Right(...) {{{2 @@ -2877,7 +2877,7 @@ function s:Right(...) let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right'] - if delim == '' + if delim ==# '' return '' endif @@ -2911,7 +2911,7 @@ function s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottomli " get the next line and see if it is commentable, otherwise it doesn't " count let theLine = getline(currentLine) - if a:countEmptyLines || theLine !~ '^[ \t]*$' + if a:countEmptyLines || theLine !~# '^[ \t]*$' if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine)) @@ -2935,8 +2935,8 @@ endfunction "Saves the current cursor position in the current buffer and the window "scroll position function s:SaveScreenState() - let t:NERDComOldPos = getpos(".") - let t:NERDComOldTopLine = line("w0") + let t:NERDComOldPos = getpos('.') + let t:NERDComOldTopLine = line('w0') endfunction " Function: s:SwapOuterMultiPartDelimsForPlaceHolders(line) {{{2 @@ -3001,10 +3001,10 @@ endfunction "FUNCTION: s:TabSpace() {{{2 "returns a string of spaces equal in length to &tabstop function s:TabSpace() - let tabSpace = "" + let tabSpace = '' let spacesPerTab = &tabstop while spacesPerTab > 0 - let tabSpace = tabSpace . " " + let tabSpace = tabSpace . ' ' let spacesPerTab = spacesPerTab - 1 endwhile return tabSpace @@ -3016,7 +3016,7 @@ endfunction " -str: the string to remove esc chars from " -escChar: the escape char to be removed function s:UnEsc(str, escChar) - return substitute(a:str, a:escChar, "", "g") + return substitute(a:str, a:escChar, '', 'g') endfunction " Function: s:UntabbedCol(line, col) {{{2 @@ -3052,7 +3052,7 @@ function! s:CreateMaps(modes, target, desc, combo) endif let menu_command .= ' ' . (strlen(a:combo) ? plug : a:target) " Execute the commands built above for each requested mode. - for mode in (a:modes == '') ? [''] : split(a:modes, '\zs') + for mode in (a:modes ==# '') ? [''] : split(a:modes, '\zs') if strlen(a:combo) execute mode . plug_start . mode . plug_end if g:NERDCreateDefaultMappings && !hasmapto(plug, mode) @@ -3060,7 +3060,7 @@ function! s:CreateMaps(modes, target, desc, combo) endif endif " Check if the user wants the menu to be displayed. - if g:NERDMenuMode != 0 + if g:NERDMenuMode !=# 0 execute mode . menu_command endif endfor @@ -3084,7 +3084,7 @@ call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') -inoremap NERDCommenterInsert :call NERDComment('i', "insert") +inoremap NERDCommenterInsert :call NERDComment('i', 'insert') " switch to/from alternative delimiters (does not use wrapper function) nnoremap NERDCommenterAltDelims :call SwitchToAlternativeDelimiters(1)