From 6f46962e507c4defc22eb23a95105e966c44f827 Mon Sep 17 00:00:00 2001 From: Mayank Sharma Date: Sun, 11 Feb 2018 09:28:20 +0530 Subject: [PATCH 1/2] Add ToggleSexyComments flag to enable sexy comments while toggling --- README.md | 3 +++ plugin/NERD_commenter.vim | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d464ad4..989b0fed 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,9 @@ let g:NERDCommentEmptyLines = 1 " Enable trimming of trailing whitespace when uncommenting let g:NERDTrimTrailingWhitespace = 1 + +" Enable Sexy Comments while Toggling. Default behaviour is normal comments. +let g:ToggleSexyComments = 1 ``` ### Default mappings diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 704da0a6..063cf0d4 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -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:NERDToggleSexyComments", 0) let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" @@ -1261,8 +1262,16 @@ function! NERDComment(mode, type) range 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) + elseif g:NERDToggleSexyComments == 1 + try + call s:CommentLinesSexy(firstLine, lastLine) + catch /NERDCommenter.Delimiters/ + call s:CommentLines(forceNested, g:NERDDefaultAlign, firstLine, lastLine) + catch /NERDCommenter.Nesting/ + call s:NerdEcho("Sexy comment aborted. Nested sexy cannot be nested", 0) + endtry + else + call s:CommentLinesToggle(forceNested, firstLine, lastLine) endif elseif a:type ==? 'Minimal' From 9076d51ecef35f4f4be930b2d35477d53ee2a6d1 Mon Sep 17 00:00:00 2001 From: Mayank Sharma Date: Fri, 17 May 2019 12:02:23 +0530 Subject: [PATCH 2/2] SexyToggle and NormalToggle, two new modes have been added. Both can be mapped to a single key to have even better commenting. --- plugin/NERD_commenter.vim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 063cf0d4..d973fde0 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -87,7 +87,7 @@ let s:delimiterMap = { \ 'applescript': { 'left': '--', 'leftAlt': '(*', 'rightAlt': '*)' }, \ 'armasm': { 'left': ';' }, \ 'asciidoc': { 'left': '//' }, - \ 'asm': { 'left': ';', 'leftAlt': '#' }, + \ 'asm': { 'left': '#', 'leftAlt': ';' }, \ 'asm68k': { 'left': ';' }, \ 'asn': { 'left': '--' }, \ 'asp': { 'left': '%', 'leftAlt': '%*', 'rightAlt': '*%' }, @@ -1257,7 +1257,7 @@ function! NERDComment(mode, type) range call s:NerdEcho("Sexy comment aborted. Nested sexy cannot be nested", 0) endtry - elseif a:type ==? 'Toggle' + elseif a:type ==? 'SexyToggle' let theLine = getline(firstLine) if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) @@ -1274,6 +1274,18 @@ function! NERDComment(mode, type) range call s:CommentLinesToggle(forceNested, firstLine, lastLine) endif + elseif a:type ==? 'NormalToggle' + 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) + elseif g:NERDToggleSexyComments == 1 + call s:SwitchToAlternativeDelimiters(0) + call s:CommentLinesToggle(forceNested, firstLine, lastLine) + call s:SwitchToAlternativeDelimiters(0) + else + call s:CommentLinesToggle(forceNested, firstLine, lastLine) + endif elseif a:type ==? 'Minimal' try call s:CommentLinesMinimal(firstLine, lastLine) @@ -3033,7 +3045,8 @@ function! s:CreateMaps(modes, target, desc, combo) endfor endfunction call s:CreateMaps('nx', 'Comment', 'Comment', 'cc') -call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c') +call s:CreateMaps('nx', 'SexyToggle', 'SexyToggle', 'c') +call s:CreateMaps('nx', 'NormalToggle', 'NormalToggle', 'c') call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm') call s:CreateMaps('nx', 'Nested', 'Nested', 'cn') call s:CreateMaps('n', 'ToEOL', 'To EOL', 'c$')