mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-11-20 07:23:40 -05:00
toggle comment depends on previous line
like Ctrl+/ in pycharm, vscode and so on
This commit is contained in:
@@ -1019,7 +1019,8 @@ function! s:CommentLinesToggle(forceNested, firstLine, lastLine) abort
|
|||||||
let currentLine = a:firstLine
|
let currentLine = a:firstLine
|
||||||
|
|
||||||
let align = g:NERDDefaultAlign
|
let align = g:NERDDefaultAlign
|
||||||
let leftAlignIndx = align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
|
let lookBehind = align ==# 'previous' && currentLine != 1 && s:IsCommentedFromStartOfLine(s:Left(), getline(currentLine - 1))
|
||||||
|
let leftAlignIndx = align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine - lookBehind, a:lastLine)
|
||||||
let rightAlignIndx = s:RightMostIndx(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}))
|
let rightAlignIndx = rightAlignIndx + strlen(s:Left({'space': 1}))
|
||||||
|
|
||||||
@@ -1037,7 +1038,7 @@ function! s:CommentLinesToggle(forceNested, firstLine, lastLine) abort
|
|||||||
let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine)
|
let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if align ==# 'left' || align ==# 'start' || align ==# 'both'
|
if align ==# 'left' || align ==# 'start' || align ==# 'both' || align ==# 'previous'
|
||||||
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx)
|
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx)
|
||||||
else
|
else
|
||||||
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)
|
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)
|
||||||
|
|||||||
@@ -503,8 +503,8 @@ change the filetype back: >
|
|||||||
style sexy comments.
|
style sexy comments.
|
||||||
|
|
||||||
|'NERDDefaultAlign'| Specifies the default alignment to use,
|
|'NERDDefaultAlign'| Specifies the default alignment to use,
|
||||||
one of 'none', 'left', 'start', or
|
one of 'none', 'left', 'start', 'both'
|
||||||
'both'.
|
or 'previous'.
|
||||||
|
|
||||||
|'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check
|
|'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check
|
||||||
all selected lines is commented or not.
|
all selected lines is commented or not.
|
||||||
@@ -784,7 +784,7 @@ deleted when uncommenting a line.
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'NERDDefaultAlign'*
|
*'NERDDefaultAlign'*
|
||||||
Values: 'none', 'left', 'start', 'both'
|
Values: 'none', 'left', 'start', 'both', 'previous'.
|
||||||
Default 'none'.
|
Default 'none'.
|
||||||
|
|
||||||
Specifies the default alignment to use when inserting comments.
|
Specifies the default alignment to use when inserting comments.
|
||||||
|
|||||||
Reference in New Issue
Block a user