mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-11-10 10:43:48 -05:00
Compare commits
29 Commits
2.5.2
...
houl-autol
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0d58015ca | ||
|
|
c888c82828 | ||
|
|
20f9e88395 | ||
|
|
17b68e47d7 | ||
|
|
67950d4b5d | ||
|
|
f46226bcd6 | ||
|
|
5100f47542 | ||
|
|
5ac43900e9 | ||
|
|
3427b2f4ef | ||
|
|
371e4d0e09 | ||
|
|
d24868bc85 | ||
|
|
fdf950f20b | ||
|
|
f9dd87271a | ||
|
|
8718240a51 | ||
|
|
f18bb5b223 | ||
|
|
9d1b1d5827 | ||
|
|
14004e00e0 | ||
|
|
c5bf6053f3 | ||
|
|
5fce03e259 | ||
|
|
e935614365 | ||
|
|
9b5b930b72 | ||
|
|
398a3e22a4 | ||
|
|
b4827d552e | ||
|
|
0b2a2b0641 | ||
|
|
cb8527ed3f | ||
|
|
032143ad23 | ||
|
|
f5571fd82f | ||
|
|
3ebd9b56ff | ||
|
|
80eb7ff3fd |
@@ -1,5 +1,5 @@
|
||||
" ============================================================================
|
||||
" File: NERD_commenter.vim
|
||||
" File: nerdcommenter.vim
|
||||
" Description: vim global plugin that provides easy code commenting
|
||||
" Author: Martin Grenfell <martin.grenfell at gmail dot com>
|
||||
" Maintainer: Caleb Maclennan <caleb@alerque.com>
|
||||
@@ -14,14 +14,7 @@
|
||||
" ============================================================================
|
||||
|
||||
" Section: script init stuff {{{1
|
||||
if exists("loaded_nerd_comments")
|
||||
finish
|
||||
endif
|
||||
if v:version < 700
|
||||
echoerr "NERDCommenter: this plugin requires vim >= 7. DOWNLOAD IT! You'll thank me later!"
|
||||
finish
|
||||
endif
|
||||
let loaded_nerd_comments = 1
|
||||
let nerdcommenter#loaded = 1
|
||||
|
||||
" Function: s:InitVariable() function {{{2
|
||||
" This function is used to initialise a given variable to a given value. The
|
||||
@@ -35,7 +28,7 @@ let loaded_nerd_comments = 1
|
||||
" 1 if the var is set, 0 otherwise
|
||||
function s:InitVariable(var, value)
|
||||
if !exists(a:var)
|
||||
execute 'let ' . a:var . ' = ' . "'" . a:value . "'"
|
||||
execute 'let ' . a:var . ' = ' . string(a:value)
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
@@ -54,7 +47,6 @@ call s:InitVariable("g:NERDBlockComIgnoreEmpty", 0)
|
||||
call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0)
|
||||
call s:InitVariable("g:NERDCommentEmptyLines", 0)
|
||||
call s:InitVariable("g:NERDCompactSexyComs", 0)
|
||||
call s:InitVariable("g:NERDCreateDefaultMappings", 1)
|
||||
call s:InitVariable("g:NERDDefaultNesting", 1)
|
||||
call s:InitVariable("g:NERDMenuMode", 3)
|
||||
call s:InitVariable("g:NERDLPlace", "[>")
|
||||
@@ -66,6 +58,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="[]#*$%'\" ?`!&();<>\\"
|
||||
|
||||
@@ -144,7 +137,7 @@ let s:delimiterMap = {
|
||||
\ 'desktop': { 'left': '#' },
|
||||
\ 'dhcpd': { 'left': '#' },
|
||||
\ 'diff': { 'left': '#' },
|
||||
\ 'django': { 'left': '<!--', 'right': '-->', 'leftAlt': '{#', 'rightAlt': '#}' },
|
||||
\ 'django': { 'left': '{% comment %}', 'right': '{% endcomment %}', 'leftAlt': '{#', 'rightAlt': '#}' },
|
||||
\ 'dns': { 'left': ';' },
|
||||
\ 'docbk': { 'left': '<!--', 'right': '-->' },
|
||||
\ 'dockerfile': { 'left': '#' },
|
||||
@@ -172,6 +165,7 @@ let s:delimiterMap = {
|
||||
\ 'exports': { 'left': '#' },
|
||||
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
|
||||
\ 'fancy': { 'left': '#' },
|
||||
\ 'faust': { 'left': '//' },
|
||||
\ 'fgl': { 'left': '#' },
|
||||
\ 'focexec': { 'left': '-*' },
|
||||
\ 'form': { 'left': '*' },
|
||||
@@ -206,7 +200,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': ' --}}' },
|
||||
@@ -215,7 +209,7 @@ let s:delimiterMap = {
|
||||
\ 'hog': { 'left': '#' },
|
||||
\ 'hostsaccess': { 'left': '#' },
|
||||
\ 'htmlcheetah': { 'left': '##' },
|
||||
\ 'htmldjango': { 'left': '<!--', 'right': '-->', 'leftAlt': '{#', 'rightAlt': '#}' },
|
||||
\ 'htmldjango': { 'left': '{% comment %}', 'right': '{% endcomment %}', 'leftAlt': '{#', 'rightAlt': '#}' },
|
||||
\ 'htmlos': { 'left': '#', 'right': '/#' },
|
||||
\ 'hxml': { 'left': '#' },
|
||||
\ 'hyphy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
@@ -241,6 +235,7 @@ let s:delimiterMap = {
|
||||
\ 'jproperties': { 'left': '#' },
|
||||
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
||||
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
||||
\ 'kivy': { 'left': '#' },
|
||||
\ 'kix': { 'left': ';' },
|
||||
\ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'lace': { 'left': '--' },
|
||||
@@ -282,7 +277,6 @@ let s:delimiterMap = {
|
||||
\ 'mkd': { 'left': '<!---', 'right': '-->' },
|
||||
\ 'mma': { 'left': '(*', 'right': '*)' },
|
||||
\ 'model': { 'left': '$', 'right': '$' },
|
||||
\ 'moduala.': { 'left': '(*', 'right': '*)' },
|
||||
\ 'modula2': { 'left': '(*', 'right': '*)' },
|
||||
\ 'modula3': { 'left': '(*', 'right': '*)' },
|
||||
\ 'molpro': { 'left': '!' },
|
||||
@@ -364,7 +358,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': '#' },
|
||||
@@ -431,7 +425,7 @@ let s:delimiterMap = {
|
||||
\ 'tex': { 'left': '%' },
|
||||
\ 'texinfo': { 'left': "@c " },
|
||||
\ 'texmf': { 'left': '%' },
|
||||
\ 'tf': { 'left': ';' },
|
||||
\ 'tf': { 'left': '#' },
|
||||
\ 'tidy': { 'left': '#' },
|
||||
\ 'tli': { 'left': '#' },
|
||||
\ 'tmux': { 'left': '#' },
|
||||
@@ -996,7 +990,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
|
||||
@@ -1022,7 +1020,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)
|
||||
@@ -1186,12 +1188,12 @@ function s:InvertComment(firstLine, lastLine)
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! NERDCommentIsLineCommented(lineNo)
|
||||
function! nerdcommenter#IsLineCommented(lineNo)
|
||||
let theLine = getline(a:lineNo)
|
||||
return s:IsInSexyComment(a:lineNo) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
||||
endfunction
|
||||
|
||||
" Function: NERDComment(mode, type) function {{{2
|
||||
" Function: nerdcommenter#Comment(mode, type) function {{{2
|
||||
" This function is a Wrapper for the main commenting functions
|
||||
"
|
||||
" Args:
|
||||
@@ -1200,7 +1202,7 @@ endfunction
|
||||
" -type: the type of commenting requested. Can be 'Sexy', 'Invert',
|
||||
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
|
||||
" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
|
||||
function! NERDComment(mode, type) range
|
||||
function! nerdcommenter#Comment(mode, type) range
|
||||
if exists('*NERDCommenter_before')
|
||||
exe "call NERDCommenter_before()"
|
||||
endif
|
||||
@@ -1270,8 +1272,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
|
||||
@@ -1315,7 +1317,7 @@ function! NERDComment(mode, type) range
|
||||
else
|
||||
normal! yy
|
||||
endif
|
||||
execute firstLine .','. lastLine .'call NERDComment("'. a:mode .'", "Comment")'
|
||||
execute firstLine .','. lastLine .'call nerdcommenter#Comment("'. a:mode .'", "Comment")'
|
||||
endif
|
||||
|
||||
call s:RecoverStateAfterLineComment(state)
|
||||
@@ -3010,17 +3012,21 @@ endfunction
|
||||
" Section: Comment mapping and menu item setup {{{1
|
||||
" ===========================================================================
|
||||
|
||||
function! nerdcommenter#Plug(target)
|
||||
return "\<Plug>NERDCommenter". a:target
|
||||
endfunction
|
||||
|
||||
" Create menu items for the specified modes. If a:combo is not empty, then
|
||||
" also define mappings and show a:combo in the menu items.
|
||||
function! s:CreateMaps(modes, target, desc, combo)
|
||||
" Build up a map command like
|
||||
" 'noremap <silent> <plug>NERDCommenterComment :call NERDComment("n", "Comment")'
|
||||
let plug = '<plug>NERDCommenter' . a:target
|
||||
let plug_start = 'noremap <silent> ' . plug . ' :call NERDComment("'
|
||||
let plug_end = '", "' . a:target . '")<cr>'
|
||||
" 'noremap <silent> <Plug>NERDCommenterComment :call nerdcommenter#Comment("n", "Comment")'
|
||||
let plug = '<Plug>NERDCommenter' . a:target
|
||||
let plug_start = 'noremap <silent> ' . plug . ' :call nerdcommenter#Comment("'
|
||||
let plug_end = '", "' . a:target . '")<CR>'
|
||||
" Build up a menu command like
|
||||
" 'menu <silent> comment.Comment<Tab>\\cc <plug>NERDCommenterComment'
|
||||
let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'],
|
||||
" 'menu <silent> comment.Comment<Tab>\\cc <Plug>NERDCommenterComment'
|
||||
let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment', '&Plugin.Nerd\ &Commenter'],
|
||||
\ g:NERDMenuMode, '')
|
||||
let menu_command = 'menu <silent> ' . menuRoot . '.' . escape(a:desc, ' ')
|
||||
if strlen(a:combo)
|
||||
@@ -3032,9 +3038,6 @@ function! s:CreateMaps(modes, target, desc, combo)
|
||||
for mode in (a:modes == '') ? [''] : split(a:modes, '\zs')
|
||||
if strlen(a:combo)
|
||||
execute mode . plug_start . mode . plug_end
|
||||
if g:NERDCreateDefaultMappings && !hasmapto(plug, mode)
|
||||
execute mode . 'map <leader>' . a:combo . ' ' . plug
|
||||
endif
|
||||
endif
|
||||
" Check if the user wants the menu to be displayed.
|
||||
if g:NERDMenuMode != 0
|
||||
@@ -3043,7 +3046,7 @@ function! s:CreateMaps(modes, target, desc, combo)
|
||||
endfor
|
||||
endfunction
|
||||
call s:CreateMaps('nx', 'Comment', 'Comment', 'cc')
|
||||
call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c<space>')
|
||||
call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c<Space>')
|
||||
call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm')
|
||||
call s:CreateMaps('nx', 'Nested', 'Nested', 'cn')
|
||||
call s:CreateMaps('n', 'ToEOL', 'To EOL', 'c$')
|
||||
@@ -3061,13 +3064,15 @@ call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '')
|
||||
call s:CreateMaps('', ':', '-Sep3-', '')
|
||||
call s:CreateMaps('', ':help NERDCommenterContents<CR>', 'Help', '')
|
||||
|
||||
inoremap <silent> <plug>NERDCommenterInsert <SPACE><BS><ESC>:call NERDComment('i', "insert")<CR>
|
||||
inoremap <silent> <Plug>NERDCommenterInsert <Space><BS><Esc>:call nerdcommenter#Comment('i', "insert")<CR>
|
||||
|
||||
" switch to/from alternative delimiters (does not use wrapper function)
|
||||
nnoremap <plug>NERDCommenterAltDelims :call <SID>SwitchToAlternativeDelimiters(1)<cr>
|
||||
nnoremap <Plug>NERDCommenterAltDelims :call <SID>SwitchToAlternativeDelimiters(1)<CR>
|
||||
|
||||
" This is a workaround to enable lazy-loading from supported plugin managers:
|
||||
" See https://github.com/scrooloose/nerdcommenter/issues/176
|
||||
call s:SetUpForNewFiletype(&filetype, 1)
|
||||
if !has('vim_starting')
|
||||
call s:SetUpForNewFiletype(&filetype, 1)
|
||||
endif
|
||||
|
||||
" vim: set foldmethod=marker :
|
||||
@@ -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*
|
||||
|
||||
Reference in New Issue
Block a user