mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-11-15 05:03:47 -05:00
Add option to allow deleting trailing whitespace (#251)
Add option g:NERDTrimTrailingWhitespace to allow deleting trailing whitespace when uncommenting a line.
This commit is contained in:
committed by
Caleb Maclennan
parent
e1aeec12be
commit
e2d47bec26
@@ -64,6 +64,7 @@ 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)
|
||||
|
||||
let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\"
|
||||
|
||||
@@ -1419,6 +1420,15 @@ function s:RecoverStateAfterLineComment(state)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:TrimTrailingWhitespace(line) {{{2
|
||||
" This function removes all the trailing whitespace
|
||||
" Args:
|
||||
" -line: the target line
|
||||
function s:TrimTrailingWhitespace(line)
|
||||
let toReturn = substitute(a:line, '\s\+$', '', 'g')
|
||||
return toReturn
|
||||
endfunction
|
||||
|
||||
" Function: s:UncommentLines(topLine, bottomLine) {{{2
|
||||
" This function uncomments the given lines
|
||||
"
|
||||
@@ -1511,6 +1521,10 @@ function s:UncommentLinesSexy(topline, bottomline)
|
||||
|
||||
let theLine = s:ConvertLeadingWhiteSpace(theLine)
|
||||
|
||||
if g:NERDTrimTrailingWhitespace == 1
|
||||
let theLine = s:TrimTrailingWhitespace(theLine)
|
||||
endif
|
||||
|
||||
" move onto the next line
|
||||
call setline(currentLine, theLine)
|
||||
let currentLine = currentLine + 1
|
||||
@@ -1652,6 +1666,10 @@ function s:UncommentLineNormal(line)
|
||||
|
||||
let line = s:ConvertLeadingWhiteSpace(line)
|
||||
|
||||
if g:NERDTrimTrailingWhitespace == 1
|
||||
let line = s:TrimTrailingWhitespace(line)
|
||||
endif
|
||||
|
||||
return line
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user