From 17b68e47d781b9fcbf1c77495e535eab366f20ca Mon Sep 17 00:00:00 2001 From: Jingchang Shi Date: Wed, 17 Apr 2019 17:11:07 +0800 Subject: [PATCH] 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)