Skip to content

Commit

Permalink
toggle comment depends on previous line
Browse files Browse the repository at this point in the history
like Ctrl+/ in pycharm, vscode and so on
  • Loading branch information
Maksim Nikulin committed Nov 26, 2023
1 parent da948e1 commit 8608a21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions autoload/nerdcommenter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,8 @@ function! s:CommentLinesToggle(forceNested, firstLine, lastLine) abort
let currentLine = a:firstLine

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 = rightAlignIndx + strlen(s:Left({'space': 1}))

Expand All @@ -1037,7 +1038,7 @@ function! s:CommentLinesToggle(forceNested, firstLine, lastLine) abort
let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine)
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)
else
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)
Expand Down
6 changes: 3 additions & 3 deletions doc/nerdcommenter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ change the filetype back: >
style sexy comments.

|'NERDDefaultAlign'| Specifies the default alignment to use,
one of 'none', 'left', 'start', or
'both'.
one of 'none', 'left', 'start', 'both'
or 'previous'.

|'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check
all selected lines is commented or not.
Expand Down Expand Up @@ -784,7 +784,7 @@ deleted when uncommenting a line.

------------------------------------------------------------------------------
*'NERDDefaultAlign'*
Values: 'none', 'left', 'start', 'both'
Values: 'none', 'left', 'start', 'both', 'previous'.
Default 'none'.

Specifies the default alignment to use when inserting comments.
Expand Down

0 comments on commit 8608a21

Please sign in to comment.