From e679d8a34193d1ac93b98ed792cdde7c9b1104a1 Mon Sep 17 00:00:00 2001 From: Jiaobuzuji Date: Sat, 3 Mar 2018 20:16:47 +0800 Subject: [PATCH 01/12] Add support for 'sdc' filetype (#327) --- plugin/NERD_commenter.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 704da0a..1591449 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -375,6 +375,7 @@ let s:delimiterMap = { \ 'scons': { 'left': '#' }, \ 'scsh': { 'left': ';' }, \ 'scss': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, + \ 'sdc': { 'left': '#' }, \ 'sed': { 'left': '#' }, \ 'sgmldecl': { 'left': '--', 'right': '--' }, \ 'sgmllnx': { 'left': '' }, From 9a32fd2534427f7a1dcfe22e9c0ea6b67b6dbe78 Mon Sep 17 00:00:00 2001 From: fcying Date: Thu, 21 Jun 2018 16:06:22 +0800 Subject: [PATCH 02/12] Add NERDToggleCheckAllLines option to NERDCommenterToggle (#334) --- README.md | 3 +++ doc/NERD_commenter.txt | 12 ++++++++++++ plugin/NERD_commenter.vim | 26 ++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2d464ad..a64b068 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 NERDCommenterToggle to check all selected lines is commented or not +let g:NERDToggleCheckAllLines = 1 ``` ### Default mappings diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index d37507a..daf8b96 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -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* @@ -800,6 +803,15 @@ When this option is set to 1, comments are nested automatically. That is, if you hit ||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* diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 1591449..a4ada45 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:NERDToggleCheckAllLines", 0) let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" @@ -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' From f9dd87271a7147d82c6cf20071478e6d8019c3e8 Mon Sep 17 00:00:00 2001 From: Zachary Churchill Date: Fri, 27 Jul 2018 23:52:07 -0400 Subject: [PATCH 03/12] Swap default comment style to be more idiomatic of haskell (#343) See discussion at https://github.com/scrooloose/nerdcommenter/pull/343 --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index a4ada45..ee827cd 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -206,7 +206,7 @@ let s:delimiterMap = { \ 'h': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'haml': { 'left': '-#', 'leftAlt': '/' }, \ 'handlebars': { 'left': '{{!-- ', 'right': ' --}}' }, - \ 'haskell': { 'left': '{-', 'right': '-}', 'nested': 1, 'leftAlt': '--', 'nestedAlt': 1 }, + \ 'haskell': { 'left': '--', 'nested': 0, 'leftAlt': '{-', 'rightAlt': '-}', 'nestedAlt': 1 }, \ 'haxe': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'hb': { 'left': '#' }, \ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' }, From fdf950f20b3907c6a6fa0bc5c7ac0aeb567841dd Mon Sep 17 00:00:00 2001 From: keysen Date: Tue, 31 Jul 2018 19:29:13 +0200 Subject: [PATCH 04/12] Fix ruby comments, totally broken with =begin and =end (#340) --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index ee827cd..614b9d2 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -364,7 +364,7 @@ let s:delimiterMap = { \ 'robot': { 'left': '#' }, \ 'robots': { 'left': '#' }, \ 'rspec': { 'left': '#' }, - \ 'ruby': { 'left': '#', 'leftAlt': '=begin', 'rightAlt': '=end' }, + \ 'ruby': { 'left': '#' }, \ 'rust': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'sa': { 'left': '--' }, \ 'samba': { 'left': ';', 'leftAlt': '#' }, From d24868bc85de599ee2424ca93aa5f6991bd3128c Mon Sep 17 00:00:00 2001 From: Maarten van der Hoef Date: Mon, 3 Dec 2018 14:22:57 +0100 Subject: [PATCH 05/12] Terraform replacing Transcript File (#350) --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 614b9d2..31ea0d5 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -431,7 +431,7 @@ let s:delimiterMap = { \ 'tex': { 'left': '%' }, \ 'texinfo': { 'left': "@c " }, \ 'texmf': { 'left': '%' }, - \ 'tf': { 'left': ';' }, + \ 'tf': { 'left': '#' }, \ 'tidy': { 'left': '#' }, \ 'tli': { 'left': '#' }, \ 'tmux': { 'left': '#' }, From 371e4d0e099abb86a3016fefd1efae28a4e13856 Mon Sep 17 00:00:00 2001 From: glegodais Date: Wed, 26 Dec 2018 12:11:50 +0100 Subject: [PATCH 06/12] Add support for Faust (#354) --- plugin/NERD_commenter.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 31ea0d5..6db80e4 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -172,6 +172,7 @@ let s:delimiterMap = { \ 'exports': { 'left': '#' }, \ 'factor': { 'left': '! ', 'leftAlt': '!# ' }, \ 'fancy': { 'left': '#' }, + \ 'faust': { 'left': '//' }, \ 'fgl': { 'left': '#' }, \ 'focexec': { 'left': '-*' }, \ 'form': { 'left': '*' }, From 3427b2f4ef5f28c9886b7fed54eb9b1cd417fbdf Mon Sep 17 00:00:00 2001 From: MeNsaaH Date: Mon, 4 Feb 2019 10:13:20 +0100 Subject: [PATCH 07/12] updated Django comments (#359) * updated Django comments * Adding alternate comments for django --- plugin/NERD_commenter.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 6db80e4..46a78b3 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -144,7 +144,7 @@ let s:delimiterMap = { \ 'desktop': { 'left': '#' }, \ 'dhcpd': { 'left': '#' }, \ 'diff': { 'left': '#' }, - \ 'django': { 'left': '', 'leftAlt': '{#', 'rightAlt': '#}' }, + \ 'django': { 'left': '{% comment %}', 'right': '{% endcomment %}', 'leftAlt': '{#', 'rightAlt': '#}' }, \ 'dns': { 'left': ';' }, \ 'docbk': { 'left': '' }, \ 'dockerfile': { 'left': '#' }, @@ -216,7 +216,7 @@ let s:delimiterMap = { \ 'hog': { 'left': '#' }, \ 'hostsaccess': { 'left': '#' }, \ 'htmlcheetah': { 'left': '##' }, - \ 'htmldjango': { 'left': '', 'leftAlt': '{#', 'rightAlt': '#}' }, + \ 'htmldjango': { 'left': '{% comment %}', 'right': '{% endcomment %}', 'leftAlt': '{#', 'rightAlt': '#}' }, \ 'htmlos': { 'left': '#', 'right': '/#' }, \ 'hxml': { 'left': '#' }, \ 'hyphy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, From 5ac43900e91291cf3045c3858db0836d70f5ee12 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 14 Feb 2019 09:48:49 +0300 Subject: [PATCH 08/12] Strip trailing whitespace --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 46a78b3..918fbb6 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -172,7 +172,7 @@ let s:delimiterMap = { \ 'exports': { 'left': '#' }, \ 'factor': { 'left': '! ', 'leftAlt': '!# ' }, \ 'fancy': { 'left': '#' }, - \ 'faust': { 'left': '//' }, + \ 'faust': { 'left': '//' }, \ 'fgl': { 'left': '#' }, \ 'focexec': { 'left': '-*' }, \ 'form': { 'left': '*' }, From 5100f47542cb9cab120f172816471e6c3e242278 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 14 Feb 2019 09:50:24 +0300 Subject: [PATCH 09/12] Add kivy file format, fixes #361 --- plugin/NERD_commenter.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 918fbb6..c787a0c 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -242,6 +242,7 @@ let s:delimiterMap = { \ 'jproperties': { 'left': '#' }, \ 'jsp': { 'left': '<%--', 'right': '--%>' }, \ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' }, + \ 'kivy': { 'left': '#' }, \ 'kix': { 'left': ';' }, \ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'lace': { 'left': '--' }, From f46226bcd679a2d656b3179c54cc6b88f1db3b27 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 7 Mar 2019 12:00:42 +0300 Subject: [PATCH 10/12] Remove apparently bogus filetype I can't find any record of this being a legitimate filetype. It isn't in vim or nvim's filetype detection system and nothing comes up in search. If it's legit somebody can complain and we'll add it back, but it seems likely this was left over from a fat-fingered mistake during the initial development of the plugin. Fixes #363 --- plugin/NERD_commenter.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index c787a0c..60c0e31 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -284,7 +284,6 @@ let s:delimiterMap = { \ 'mkd': { 'left': '' }, \ 'mma': { 'left': '(*', 'right': '*)' }, \ 'model': { 'left': '$', 'right': '$' }, - \ 'moduala.': { 'left': '(*', 'right': '*)' }, \ 'modula2': { 'left': '(*', 'right': '*)' }, \ 'modula3': { 'left': '(*', 'right': '*)' }, \ 'molpro': { 'left': '!' }, From 67950d4b5d2e78733ab085a57c897c711e5eb2dc Mon Sep 17 00:00:00 2001 From: Lane Date: Wed, 17 Apr 2019 14:49:38 +0800 Subject: [PATCH 11/12] Make g:NERDToggleCheckAllLines not check blank/whitespace-only lines (#355) --- plugin/NERD_commenter.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 60c0e31..c9e081a 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -1271,8 +1271,8 @@ function! NERDComment(mode, type) range 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) + " if have one line no comment(not include blank/whitespace-only lines), then comment all lines + if theLine =~ '[^ \t]\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) let l:commentAllLines = 1 break else From 17b68e47d781b9fcbf1c77495e535eab366f20ca Mon Sep 17 00:00:00 2001 From: Jingchang Shi Date: Wed, 17 Apr 2019 17:11:07 +0800 Subject: [PATCH 12/12] Add an option: NERDDisableTabsInBlockComm (#374) * Add an option: NERDDisableTabsInBlockComm. 1 disables adding tabs before the comment symbols in the block style. * Add doc for the new option. --- doc/NERD_commenter.txt | 24 ++++++++++++++++++++++++ plugin/NERD_commenter.vim | 13 +++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index daf8b96..5a14a4d 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -811,6 +811,30 @@ 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. +------------------------------------------------------------------------------ + *'NERDDisableTabsInBlockComm'* +Values: 0 or 1. +Default 0. + +When this option is set to 1, NERDDisableTabsInBlockComm will not add +whitespaces align the start location of the ending comment symbol with the +end location of the starting comment symbol. For example, in Fortran, the new +style will be as the following: > + close (inpt,iostat=ierr,iomsg=error_message) + call io_error(pname,input_fname,2,__LINE__,__FILE__,ierr,error_message) +< +to > + !===BEGIN===! + ! close (inpt,iostat=ierr,iomsg=error_message) + ! call io_error(pname,input_fname,2,__LINE__,__FILE__,ierr,error_message) + !===END===! +< +for the block comment style if customized comment symbols are set up in vimrc +file by the following line > + let g:NERDCustomDelimiters = { + \ 'fortran':{'left':'!','leftAlt':'!===BEGIN===!','rightAlt':'!===END===!'} + \ } +< ------------------------------------------------------------------------------ 3.3 Default delimiter customisation *NERDComDefaultDelims* diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index c9e081a..5005b22 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -66,6 +66,7 @@ call s:InitVariable("g:NERDSpaceDelims", 0) call s:InitVariable("g:NERDDefaultAlign", "none") call s:InitVariable("g:NERDTrimTrailingWhitespace", 0) call s:InitVariable("g:NERDToggleCheckAllLines", 0) +call s:InitVariable("g:NERDDisableTabsInBlockComm", 0) let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" @@ -997,7 +998,11 @@ function s:CommentLinesSexy(topline, bottomline) " the lines down when we added the left delimiter call cursor(a:bottomline+1, 1) execute 'normal! o' - let theLine = repeat(' ', leftAlignIndx) . repeat(' ', strlen(left)-strlen(sexyComMarker)) . right + if g:NERDDisableTabsInBlockComm + let theLine = repeat(' ', leftAlignIndx) . right + else + let theLine = repeat(' ', leftAlignIndx) . repeat(' ', strlen(left)-strlen(sexyComMarker)) . right + endif " Make sure tabs are respected if !&expandtab @@ -1023,7 +1028,11 @@ function s:CommentLinesSexy(topline, bottomline) endif " add the sexyComMarker - let theLine = repeat(' ', leftAlignIndx) . repeat(' ', strlen(left)-strlen(sexyComMarker)) . sexyComMarkerSpaced . strpart(theLine, leftAlignIndx) + if g:NERDDisableTabsInBlockComm + let theLine = repeat(' ', leftAlignIndx) . sexyComMarkerSpaced . strpart(theLine, leftAlignIndx) + else + let theLine = repeat(' ', leftAlignIndx) . repeat(' ', strlen(left)-strlen(sexyComMarker)) . sexyComMarkerSpaced . strpart(theLine, leftAlignIndx) + endif if lineHasTabs let theLine = s:ConvertLeadingSpacesToTabs(theLine)