Skip to content

Commit

Permalink
Add NERDToggleCheckAllLines option to NERDCommenterToggle (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcying authored and alerque committed Jun 21, 2018
1 parent e679d8a commit 9a32fd2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" Enable NERDCommenterToggle to check all selected lines is commented or not
let g:NERDToggleCheckAllLines = 1
```

### Default mappings
Expand Down
12 changes: 12 additions & 0 deletions doc/NERD_commenter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ change the filetype back: >
one of 'none', 'left', 'start', or
'both'.

|'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check
all selected lines is commented or not.

------------------------------------------------------------------------------
4.3 Options details *NERDComOptionsDetails*

Expand Down Expand Up @@ -800,6 +803,15 @@ When this option is set to 1, comments are nested automatically. That is, if
you hit |<Leader>|cc on a line that is already commented it will be commented
again.

------------------------------------------------------------------------------
*'NERDToggleCheckAllLines'*
Values: 0 or 1.
Default 0.

When this option is set to 1, NERDCommenterToggle will check all selected line,
if there have oneline not be commented, then comment all lines.


------------------------------------------------------------------------------
3.3 Default delimiter customisation *NERDComDefaultDelims*

Expand Down
26 changes: 22 additions & 4 deletions plugin/NERD_commenter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ 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)

let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\"

Expand Down Expand Up @@ -1258,12 +1259,29 @@ function! NERDComment(mode, type) range
endtry

elseif a:type ==? 'Toggle'
let theLine = getline(firstLine)

if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
call s:UncommentLines(firstLine, lastLine)
if g:NERDToggleCheckAllLines ==# 0
let theLine = getline(firstLine)
if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
call s:UncommentLines(firstLine, lastLine)
else
call s:CommentLinesToggle(forceNested, firstLine, lastLine)
endif
else
let l:commentAllLines = 0
for i in range(firstLine, lastLine)
let theLine = getline(i)
" if have one line no comment, then comment all lines
if !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
let l:commentAllLines = 1
break
else
endif
endfor
if l:commentAllLines ==# 1
call s:CommentLinesToggle(forceNested, firstLine, lastLine)
else
call s:UncommentLines(firstLine, lastLine)
endif
endif

elseif a:type ==? 'Minimal'
Expand Down

0 comments on commit 9a32fd2

Please sign in to comment.