Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggle comment depends on previous line #529

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading