mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-11-08 09:53:47 -05:00
Compare commits
45 Commits
2.6.0
...
7361e41811
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7361e41811 | ||
|
|
66c07e4083 | ||
|
|
3f860f2d98 | ||
|
|
c9b1078807 | ||
|
|
7bb1f72e80 | ||
|
|
fea637c3c2 | ||
|
|
e361a44230 | ||
|
|
da948e160d | ||
|
|
c52b6e731c | ||
|
|
d2e21d417f | ||
|
|
ab2ae4d502 | ||
|
|
844b211a4c | ||
|
|
b0b09ea46c | ||
|
|
2045211689 | ||
|
|
277bdfc679 | ||
|
|
1fe9e1cfea | ||
|
|
e23f55e735 | ||
|
|
91499c76a7 | ||
|
|
bd1a29536d | ||
|
|
c6766698d8 | ||
|
|
c5b0f78820 | ||
|
|
78029a0e90 | ||
|
|
457b383767 | ||
|
|
d069f7fb56 | ||
|
|
06f6166e5d | ||
|
|
c406bba57d | ||
|
|
ea6a4f76fa | ||
|
|
1caf560df1 | ||
|
|
98cc4a2d64 | ||
|
|
f575c18d05 | ||
|
|
fd2114b46d | ||
|
|
fe74a1b890 | ||
|
|
60f3a2bc2b | ||
|
|
2a0a05ff98 | ||
|
|
6d30ebcd42 | ||
|
|
f8671f783b | ||
|
|
ec002e8f5d | ||
|
|
f9c5f0fbda | ||
|
|
ac512fe158 | ||
|
|
867618364f | ||
|
|
97317fc319 | ||
|
|
37298c471e | ||
|
|
9fffd4c022 | ||
|
|
2e7a775dd2 | ||
|
|
c7c99edfb7 |
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
### 2.7.0
|
||||
|
||||
* Support for many more filetypes
|
||||
* Sort out race condition when using utility functions directly
|
||||
* Fixup undo support when commenting results in cursor moves
|
||||
* Refactor comment insertion code
|
||||
|
||||
### 2.6.0
|
||||
|
||||
* Refactor code to run as autoload plugin
|
||||
|
||||
10
README.md
10
README.md
@@ -68,10 +68,12 @@ git clone https://github.com/preservim/nerdcommenter.git
|
||||
(For Neovim, change `~/.vim/` to `~/.config/nvim/`.)
|
||||
|
||||
```sh
|
||||
curl -fLo ~/.vim/plugin/NERD_Commenter.vim --create-dirs \
|
||||
curl -fLo ~/.vim/plugin/nerdcommenter.vim --create-dirs \
|
||||
https://raw.githubusercontent.com/preservim/nerdcommenter/master/plugin/nerdcommenter.vim
|
||||
curl -fLo ~/.vim/doc/NERD_Commenter.txt --create-dirs \
|
||||
curl -fLo ~/.vim/doc/nerdcommenter.txt --create-dirs \
|
||||
https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/nerdcommenter.txt
|
||||
curl -fLo ~/.vim/autoload/nerdcommenter.vim --create-dirs \
|
||||
https://raw.githubusercontent.com/preservim/nerdcommenter/master/autoload/nerdcommenter.vim
|
||||
```
|
||||
</details>
|
||||
|
||||
@@ -201,8 +203,8 @@ Most of the following mappings are for normal/visual mode only. The **|NERDComme
|
||||
|
||||
While the plugin does not directly support motions, you can leverage its support for selections to do something very similar. For example, to add motions to toggle comments on the paragraph text object you could use:
|
||||
```vim
|
||||
nnoremap <silent> <leader>c} V}:call NERDComment('x', 'toggle')<CR>
|
||||
nnoremap <silent> <leader>c{ V{:call NERDComment('x', 'toggle')<CR>
|
||||
nnoremap <silent> <leader>c} V}:call nerdcommenter#Comment('x', 'toggle')<CR>
|
||||
nnoremap <silent> <leader>c{ V{:call nerdcommenter#Comment('x', 'toggle')<CR>
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
@@ -15,6 +15,7 @@ let s:delimiterMap = {
|
||||
\ 'ada': { 'left': '--', 'leftAlt': '-- ' },
|
||||
\ 'ahdl': { 'left': '--' },
|
||||
\ 'ahk': { 'left': ';', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'alloy': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
||||
\ 'amiga': { 'left': ';' },
|
||||
\ 'aml': { 'left': '/*' },
|
||||
\ 'ampl': { 'left': '#' },
|
||||
@@ -23,6 +24,7 @@ let s:delimiterMap = {
|
||||
\ 'apachestyle': { 'left': '#' },
|
||||
\ 'apdl': { 'left': '!' },
|
||||
\ 'applescript': { 'left': '--', 'leftAlt': '(*', 'rightAlt': '*)' },
|
||||
\ 'aptconf': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'armasm': { 'left': ';' },
|
||||
\ 'asciidoc': { 'left': '//' },
|
||||
\ 'asm': { 'left': ';', 'leftAlt': '#' },
|
||||
@@ -33,6 +35,7 @@ let s:delimiterMap = {
|
||||
\ 'asterisk': { 'left': ';' },
|
||||
\ 'asy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'atlas': { 'left': 'C', 'right': '$' },
|
||||
\ 'ats': { 'left': '//', 'leftAlt': '(*', 'rightAlt': '*)' },
|
||||
\ 'augeas': { 'left': '(*', 'right': '*)' },
|
||||
\ 'autohotkey': { 'left': ';', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'autoit': { 'left': ';' },
|
||||
@@ -49,9 +52,11 @@ let s:delimiterMap = {
|
||||
\ 'btm': { 'left': '::' },
|
||||
\ 'c': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
||||
\ 'cabal': { 'left': '--' },
|
||||
\ 'cairo': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'calibre': { 'left': '//' },
|
||||
\ 'caos': { 'left': '*' },
|
||||
\ 'catalog': { 'left': '--', 'right': '--' },
|
||||
\ 'cel': { 'left': '//' },
|
||||
\ 'cf': { 'left': '<!---', 'right': '--->' },
|
||||
\ 'cfg': { 'left': '#' },
|
||||
\ 'cg': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
@@ -78,6 +83,7 @@ let s:delimiterMap = {
|
||||
\ 'cython': { 'left': '# ', 'leftAlt': '#' },
|
||||
\ 'd': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'dakota': { 'left': '#' },
|
||||
\ 'dart': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'dcl': { 'left': '$!' },
|
||||
\ 'debcontrol': { 'left': '#' },
|
||||
\ 'debsources': { 'left': '#' },
|
||||
@@ -85,11 +91,12 @@ let s:delimiterMap = {
|
||||
\ 'desktop': { 'left': '#' },
|
||||
\ 'dhcpd': { 'left': '#' },
|
||||
\ 'diff': { 'left': '#' },
|
||||
\ 'dts': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
||||
\ 'django': { 'left': '{% comment %}', 'right': '{% endcomment %}', 'leftAlt': '{#', 'rightAlt': '#}' },
|
||||
\ 'dns': { 'left': ';' },
|
||||
\ 'docbk': { 'left': '<!--', 'right': '-->' },
|
||||
\ 'dockerfile': { 'left': '#' },
|
||||
\ 'dosbatch': { 'left': 'REM ', 'leftAlt': '::' },
|
||||
\ 'dosbatch': { 'left': 'REM ', 'nested': 1, 'leftAlt': 'REM ', 'nestedAlt': 1 },
|
||||
\ 'dosini': { 'left': ';' },
|
||||
\ 'dot': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'dracula': { 'left': ';' },
|
||||
@@ -157,6 +164,7 @@ let s:delimiterMap = {
|
||||
\ 'haxe': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'hb': { 'left': '#' },
|
||||
\ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' },
|
||||
\ 'hcl': { 'left': '#', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'hive': { 'left': '-- ' },
|
||||
\ 'hocon': { 'left': '//', 'leftAlt': '#' },
|
||||
@@ -188,17 +196,20 @@ let s:delimiterMap = {
|
||||
\ 'jgraph': { 'left': '(*', 'right': '*)' },
|
||||
\ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' },
|
||||
\ 'jproperties': { 'left': '#' },
|
||||
\ 'jq': { 'left': '#' },
|
||||
\ 'json5': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'jsonc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'jsonnet': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
||||
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
||||
\ 'just' : { 'left': '#' },
|
||||
\ 'kivy': { 'left': '#' },
|
||||
\ 'kix': { 'left': ';' },
|
||||
\ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'lace': { 'left': '--' },
|
||||
\ 'laravel': { 'left': '{{--', 'right': '--}}' },
|
||||
\ 'ldif': { 'left': '#' },
|
||||
\ 'lean': { 'left': '--', 'leftAlt': '/-', 'rightAlt': '-/' },
|
||||
\ 'ledger': { 'left': '#', 'leftAlt': ';' },
|
||||
\ 'less': { 'left': '/*', 'right': '*/' },
|
||||
\ 'lhaskell': { 'left': '>{-', 'right': '-}', 'leftAlt': '>-- ' },
|
||||
@@ -271,6 +282,7 @@ let s:delimiterMap = {
|
||||
\ 'ox': { 'left': '//' },
|
||||
\ 'paludis-use-conf': { 'left': '#' },
|
||||
\ 'pandoc': { 'left': '<!--', 'right': '-->' },
|
||||
\ 'pamenv': { 'left': '#' },
|
||||
\ 'pascal': { 'left': '{', 'right': '}', 'leftAlt': '(*', 'rightAlt': '*)' },
|
||||
\ 'patran': { 'left': '$', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'pcap': { 'left': '#' },
|
||||
@@ -342,7 +354,7 @@ let s:delimiterMap = {
|
||||
\ 'sh': { 'left': '#' },
|
||||
\ 'shader_test': { 'left': '#' },
|
||||
\ 'sicad': { 'left': '*' },
|
||||
\ 'sile': { 'left': '%' },
|
||||
\ 'sile': { 'left': '%', 'leftAlt': '--' },
|
||||
\ 'simula': { 'left': '%', 'leftAlt': '--' },
|
||||
\ 'sinda': { 'left': '$' },
|
||||
\ 'skill': { 'left': ';' },
|
||||
@@ -379,6 +391,7 @@ let s:delimiterMap = {
|
||||
\ 'stan': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'stp': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
||||
\ 'supercollider': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'svelte': { 'left': '<!--', 'right': '-->' },
|
||||
\ 'swift': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
||||
\ 'systemverilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'tads': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
@@ -393,6 +406,7 @@ let s:delimiterMap = {
|
||||
\ 'texmf': { 'left': '%' },
|
||||
\ 'tf': { 'left': '#' },
|
||||
\ 'tidy': { 'left': '#' },
|
||||
\ 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' },
|
||||
\ 'tli': { 'left': '#' },
|
||||
\ 'tmux': { 'left': '#' },
|
||||
\ 'toml': { 'left': '#' },
|
||||
@@ -407,6 +421,7 @@ let s:delimiterMap = {
|
||||
\ 'txt2tags': { 'left': '%' },
|
||||
\ 'typescript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'typescriptreact': { 'left': '//', 'leftAlt': '{/*', 'rightAlt': '*/}' },
|
||||
\ 'typst': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'uc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'uc4': { 'left': '!' },
|
||||
\ 'uil': { 'left': '!' },
|
||||
@@ -414,6 +429,7 @@ let s:delimiterMap = {
|
||||
\ 'vala': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'vasp': { 'left': '!' },
|
||||
\ 'vb': { 'left': "'" },
|
||||
\ 'vcl': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
\ 'velocity': { 'left': '##', 'right': '', 'leftAlt': '#*', 'rightAlt': '*#' },
|
||||
\ 'vera': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
||||
\ 'verilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||
@@ -436,7 +452,8 @@ let s:delimiterMap = {
|
||||
\ 'xpm2': { 'left': '!' },
|
||||
\ 'xquery': { 'left': '(:', 'right': ':)' },
|
||||
\ 'yaml': { 'left': '#' },
|
||||
\ 'z8a': { 'left': ';' }
|
||||
\ 'z8a': { 'left': ';' },
|
||||
\ 'zig': { 'left': '//' }
|
||||
\ }
|
||||
|
||||
let g:NERDDelimiterMap = s:delimiterMap
|
||||
@@ -453,10 +470,6 @@ endif
|
||||
" This function is responsible for setting up buffer scoped variables for the
|
||||
" current buffer.
|
||||
function! nerdcommenter#SetUp() abort
|
||||
if exists('b:NERDCommenterDelims')
|
||||
return
|
||||
endif
|
||||
|
||||
let filetype = &filetype
|
||||
|
||||
"for compound filetypes, if we don't know how to handle the full filetype
|
||||
@@ -474,7 +487,7 @@ function! nerdcommenter#SetUp() abort
|
||||
let b:NERDSexyComMarker = ''
|
||||
|
||||
if has_key(s:delimiterMap, filetype)
|
||||
let b:NERDCommenterDelims = s:delimiterMap[filetype]
|
||||
let b:NERDCommenterDelims = copy(s:delimiterMap[filetype])
|
||||
for i in ['left', 'leftAlt', 'right', 'rightAlt']
|
||||
if !has_key(b:NERDCommenterDelims, i)
|
||||
let b:NERDCommenterDelims[i] = ''
|
||||
@@ -486,10 +499,10 @@ function! nerdcommenter#SetUp() abort
|
||||
endif
|
||||
endfor
|
||||
" if g:NERD_<filetype>_alt_style is defined, use the alternate style
|
||||
let b:NERDCommenterFirstInit = getbufvar(1,'NERDCommenterFirstInit')
|
||||
let b:NERDCommenterFirstInit = getbufvar(bufnr('%'),'NERDCommenterFirstInit')
|
||||
if exists('g:NERDAltDelims_'.filetype) && eval('g:NERDAltDelims_'.filetype) && !b:NERDCommenterFirstInit
|
||||
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
||||
let b:NERDCommenterFirstInit = 1
|
||||
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
||||
endif
|
||||
else
|
||||
let b:NERDCommenterDelims = s:CreateDelimMapFromCms()
|
||||
@@ -527,10 +540,10 @@ endfunction
|
||||
" if this function changed the delimiters or not
|
||||
" function nerdcommenter#SwitchToAlternativeDelimiters(printMsgs)
|
||||
function! nerdcommenter#SwitchToAlternativeDelimiters(printMsgs) abort
|
||||
call nerdcommenter#SetUp()
|
||||
if exists('*NERDCommenter_before')
|
||||
exe 'call NERDCommenter_before()'
|
||||
endif
|
||||
call nerdcommenter#SetUp()
|
||||
"if both of the alternative delimiters are empty then there is no
|
||||
"alternative comment style so bail out
|
||||
if b:NERDCommenterDelims['leftAlt'] ==# '' && b:NERDCommenterDelims['rightAlt'] ==# ''
|
||||
@@ -653,7 +666,7 @@ function! s:CommentBlock(top, bottom, lSide, rSide, forceNested) abort
|
||||
"alternative delimiters (if THEY are) as the comment will be better and more
|
||||
"accurate with multipart delimiters
|
||||
let switchedDelims = 0
|
||||
if !s:Multipart() && g:NERDAllowAnyVisualDelims && s:AltMultipart()
|
||||
if !s:Multipart() && !g:NERDAllowAnyVisualDelims && s:AltMultipart()
|
||||
let switchedDelims = 1
|
||||
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
||||
endif
|
||||
@@ -1070,7 +1083,7 @@ function! s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) a
|
||||
|
||||
"switch delimiters (if we can) if the current set isn't multipart
|
||||
let switchedDelims = 0
|
||||
if !s:Multipart() && s:AltMultipart() && g:NERDAllowAnyVisualDelims
|
||||
if !s:Multipart() && s:AltMultipart() && !g:NERDAllowAnyVisualDelims
|
||||
let switchedDelims = 1
|
||||
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
||||
endif
|
||||
@@ -1153,6 +1166,7 @@ endfunction
|
||||
" -lineNo: the line number of the line to check
|
||||
" Return: Number, 1 if the line is a comment, 0 else
|
||||
function! nerdcommenter#IsLineCommented(lineNo) abort
|
||||
call nerdcommenter#SetUp()
|
||||
let theLine = getline(a:lineNo)
|
||||
return s:IsInSexyComment(a:lineNo) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
||||
endfunction
|
||||
@@ -1167,10 +1181,10 @@ endfunction
|
||||
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
|
||||
" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
|
||||
function! nerdcommenter#Comment(mode, type) range abort
|
||||
call nerdcommenter#SetUp()
|
||||
if exists('*NERDCommenter_before')
|
||||
exe 'call NERDCommenter_before()'
|
||||
endif
|
||||
call nerdcommenter#SetUp()
|
||||
|
||||
let isVisual = a:mode =~# '[vsx]'
|
||||
|
||||
@@ -1303,15 +1317,16 @@ endfunction
|
||||
" Function: nerdcommenter#IsCharCommented(line, col) abort
|
||||
" Check if the character at [line, col] is inside a comment
|
||||
" Note the Comment delimeter it self is considered as part of the comment
|
||||
"
|
||||
"
|
||||
" Args:
|
||||
" -line the line number of the character
|
||||
" -col the column number of the character
|
||||
" Return: Number, 1 if the character is inside a comment, 0 if is not
|
||||
function! nerdcommenter#IsCharCommented(line, col) abort
|
||||
call nerdcommenter#SetUp()
|
||||
" Function: s:searchfor(str, line, col, direction, [maxline])
|
||||
" search str in the buffer, including the character at [line, col]
|
||||
" Args:
|
||||
" Args:
|
||||
" -str: the string for search
|
||||
" -line: the line number where search begins
|
||||
" -col: the column number where search begins
|
||||
@@ -1379,14 +1394,14 @@ function! nerdcommenter#IsCharCommented(line, col) abort
|
||||
let leftpos = s:searchfor(a:left, a:line, a:col, 1)
|
||||
if leftpos == [0, 0]
|
||||
if !blockcommented | let blockcommented = 0 | endif
|
||||
else
|
||||
else
|
||||
" call s:searchfor(a:right, a:line, a:col, 0)
|
||||
let rightpos = s:searchfor(a:right, leftpos[0], leftpos[1] + strlen(a:right) + 1, 0)
|
||||
if rightpos != [0, 0]
|
||||
if rightpos[0] < a:line
|
||||
if !blockcommented | let blockcommented = 0 | endif
|
||||
elseif rightpos[0] == a:line
|
||||
if !blockcommented
|
||||
if !blockcommented
|
||||
let blockcommented = (rightpos[1] + strlen(a:right) > a:col) ? 1 : 0
|
||||
endif
|
||||
else " rightpos > a:line
|
||||
@@ -1400,14 +1415,14 @@ function! nerdcommenter#IsCharCommented(line, col) abort
|
||||
return linecommented || blockcommented
|
||||
endfunction
|
||||
return s:checkwith(
|
||||
\ b:NERDCommenterDelims['left'],
|
||||
\ b:NERDCommenterDelims['right'],
|
||||
\ a:line,
|
||||
\ a:col) ||
|
||||
\ b:NERDCommenterDelims['left'],
|
||||
\ b:NERDCommenterDelims['right'],
|
||||
\ a:line,
|
||||
\ a:col) ||
|
||||
\ s:checkwith(
|
||||
\ b:NERDCommenterDelims['leftAlt'],
|
||||
\ b:NERDCommenterDelims['rightAlt'],
|
||||
\ a:line,
|
||||
\ b:NERDCommenterDelims['leftAlt'],
|
||||
\ b:NERDCommenterDelims['rightAlt'],
|
||||
\ a:line,
|
||||
\ a:col)
|
||||
endfunction
|
||||
|
||||
@@ -1419,46 +1434,20 @@ function! s:PlaceDelimitersAndInsBetween() abort
|
||||
let left = s:Left({'space': 1})
|
||||
let right = s:Right({'space': 1})
|
||||
|
||||
let theLine = getline('.')
|
||||
let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~# '^ *$' && !&expandtab)
|
||||
|
||||
"convert tabs to spaces and adjust the cursors column to take this into
|
||||
"account
|
||||
let untabbedCol = s:UntabbedCol(theLine, col('.'))
|
||||
call setline(line('.'), s:ConvertLeadingTabsToSpaces(theLine))
|
||||
call cursor(line('.'), untabbedCol)
|
||||
|
||||
" get the length of the right delimiter
|
||||
let lenRight = strlen(right)
|
||||
|
||||
let isDelimOnEOL = col('.') >= strlen(getline('.'))
|
||||
|
||||
" if the cursor is in the first col then we gotta insert rather than
|
||||
" append the comment delimiters here
|
||||
let insOrApp = (col('.')==1 ? 'i' : 'a')
|
||||
|
||||
" place the delimiters down. We do it differently depending on whether
|
||||
" there is a left AND right delimiter
|
||||
if lenRight > 0
|
||||
execute ':normal! ' . insOrApp . left . right
|
||||
execute ':normal! ' . lenRight . 'h'
|
||||
else
|
||||
execute ':normal! ' . insOrApp . left
|
||||
endif
|
||||
|
||||
"if needed convert spaces back to tabs and adjust the cursors col
|
||||
"accordingly
|
||||
if lineHasLeadTabs
|
||||
let tabbedCol = s:TabbedCol(getline('.'), col('.'))
|
||||
call setline(line('.'), s:ConvertLeadingSpacesToTabs(getline('.')))
|
||||
call cursor(line('.'), tabbedCol)
|
||||
endif
|
||||
|
||||
if isDelimOnEOL && lenRight ==# 0
|
||||
startinsert!
|
||||
else
|
||||
call feedkeys('a', 'ni')
|
||||
endif
|
||||
" 0. Entered insert normal mode using <C-\><C-O> (:h i_CTRL-\_CTRL-O) to
|
||||
" maintain the cursor position (from <Plug>NERDCommenterInsert).
|
||||
" 1. Enter insert mode without changing the cursor position.
|
||||
" If the cursor is on EOL (right of the last char), use 'a'.
|
||||
" Otherwise, use 'i'.
|
||||
let insert = col('.') > strlen(getline('.')) ? 'a' : 'i'
|
||||
" 2. Insert comment delimiters.
|
||||
" 3. Move the cursor to the left of the closing delimiter, without
|
||||
" breaking undo sequence.
|
||||
" 4. Enter insert normal mode again without changing the cursor position.
|
||||
" This ensures that returning to the insert mode after finishing the
|
||||
" script execution does not move the cursor.
|
||||
" ( 1 ) ( 2 ) ( 3 ) ( 4 )
|
||||
execute 'normal!' insert . left . right . repeat("\<C-G>U\<Left>", strchars(right)) . "\<C-\>\<C-O>"
|
||||
endfunction
|
||||
|
||||
" Function: s:RemoveDelimiters(left, right, line)
|
||||
@@ -1784,6 +1773,8 @@ function! s:UncommentLineNormal(line) abort
|
||||
endif
|
||||
|
||||
|
||||
let indxLeft = s:FindDelimiterIndex(s:Left(), line)
|
||||
let indxLeftAlt = s:FindDelimiterIndex(s:Left({'alt': 1}), line)
|
||||
let indxLeftPlace = s:FindDelimiterIndex(g:NERDLPlace, line)
|
||||
let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line)
|
||||
|
||||
@@ -2546,15 +2537,15 @@ function! s:IsDelimValid(delimiter, delIndx, line) abort
|
||||
|
||||
"vim comments are so fucking stupid!! Why the hell do they have comment
|
||||
"delimiters that are used elsewhere in the syntax?!?! We need to check
|
||||
"some conditions especially for vim
|
||||
if &filetype ==# 'vim'
|
||||
"some conditions especially for vim.
|
||||
"Also check &commentstring because it may be overwritten for embedded lua.
|
||||
if &filetype ==# 'vim' && &commentstring[0] ==# '"'
|
||||
if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\"))
|
||||
return 0
|
||||
endif
|
||||
|
||||
"if the delimiter is on the very first char of the line or is the
|
||||
"first non-tab/space char on the line then it is a valid comment delimiter
|
||||
if a:delIndx ==# 0 || a:line =~# "^\s\\{" . a:delIndx . "\\}\".*$"
|
||||
" if the delimiter is the first non-whitespace character, it is valid
|
||||
if a:line =~# '^\s*"'
|
||||
return 1
|
||||
endif
|
||||
|
||||
@@ -3019,18 +3010,6 @@ function! s:SwapOuterPlaceHoldersForMultiPartDelims(line) abort
|
||||
return line
|
||||
endfunction
|
||||
|
||||
" Function: s:TabbedCol(line, col)
|
||||
" Gets the col number for given line and existing col number. The new col
|
||||
" number is the col number when all leading spaces are converted to tabs
|
||||
" Args:
|
||||
" -line:the line to get the rel col for
|
||||
" -col: the abs col
|
||||
function! s:TabbedCol(line, col) abort
|
||||
let lineTruncated = strpart(a:line, 0, a:col)
|
||||
let lineSpacesToTabs = substitute(lineTruncated, s:TabSpace(), '\t', 'g')
|
||||
return strlen(lineSpacesToTabs)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:TabSpace()
|
||||
"returns a string of spaces equal in length to &tabstop
|
||||
function! s:TabSpace() abort
|
||||
@@ -3051,15 +3030,3 @@ endfunction
|
||||
function! s:UnEsc(str, escChar) abort
|
||||
return substitute(a:str, a:escChar, '', 'g')
|
||||
endfunction
|
||||
|
||||
" Function: s:UntabbedCol(line, col)
|
||||
" Takes a line and a col and returns the absolute column of col taking into
|
||||
" account that a tab is worth 3 or 4 (or whatever) spaces.
|
||||
" Args:
|
||||
" -line:the line to get the abs col for
|
||||
" -col: the col that doesn't take into account tabs
|
||||
function! s:UntabbedCol(line, col) abort
|
||||
let lineTruncated = strpart(a:line, 0, a:col)
|
||||
let lineTabsToSpaces = substitute(lineTruncated, '\t', s:TabSpace(), 'g')
|
||||
return strlen(lineTabsToSpaces)
|
||||
endfunction
|
||||
|
||||
@@ -66,7 +66,7 @@ creates a namespace so that custom commands don't interfere with Vim's
|
||||
built-in shortcuts.
|
||||
|
||||
The leader key can be mapped to whatever the user likes (see :help mapleader).
|
||||
In the definition of custom commands |<Leader>| is the placeholder for the
|
||||
In the definition of custom commands |<Leader>| is the placeholder for the
|
||||
leader key. To see the current mapping for |<Leader>| type :echo mapleader.
|
||||
If it reports an undefined variable it means the leader key is set to the
|
||||
default of '\'.
|
||||
@@ -464,38 +464,38 @@ change the filetype back: >
|
||||
|
||||
|'NERDCustomDelimiters'| Add or override delimiters for any
|
||||
filetypes.
|
||||
|
||||
|
||||
|'NERDDefaultNesting'| Tells the script to use nested comments
|
||||
by default.
|
||||
|
||||
|
||||
|'NERDMenuMode'| Specifies how the NERD commenter menu
|
||||
will appear (if at all).
|
||||
|
||||
|
||||
|'NERDLPlace'| Specifies what to use as the left
|
||||
delimiter placeholder when nesting
|
||||
comments.
|
||||
|
||||
|
||||
|'NERDUsePlaceHolders'| Specifies which filetypes may use
|
||||
placeholders when nesting comments.
|
||||
|
||||
|
||||
|'NERDRemoveAltComs'| Tells the script whether to remove
|
||||
alternative comment delimiters when
|
||||
uncommenting.
|
||||
|
||||
|
||||
|'NERDRemoveExtraSpaces'| Tells the script to always remove the
|
||||
extra spaces when uncommenting
|
||||
(regardless of whether NERDSpaceDelims
|
||||
is set).
|
||||
|
||||
|
||||
|'NERDRPlace'| Specifies what to use as the right
|
||||
delimiter placeholder when nesting
|
||||
comments.
|
||||
|
||||
|
||||
|'NERDSpaceDelims'| Specifies whether to add extra spaces
|
||||
around delimiters when commenting, and
|
||||
whether to remove them when
|
||||
uncommenting.
|
||||
|
||||
|
||||
|'NERDTrimTrailingWhitespace'| Specifies if trailing whitespace
|
||||
should be deleted when uncommenting.
|
||||
|
||||
@@ -506,11 +506,11 @@ change the filetype back: >
|
||||
one of 'none', 'left', 'start', or
|
||||
'both'.
|
||||
|
||||
|'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check
|
||||
|'NERDToggleCheckAllLines'| Enable NERDCommenterToggle to check
|
||||
all selected lines is commented or not.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
4.3 Options details *NERDCommenterOptionsDetails*
|
||||
4.2 Options details *NERDCommenterOptionsDetails*
|
||||
|
||||
To enable any of the below options you should put the given line in your
|
||||
~/.vimrc
|
||||
@@ -826,7 +826,7 @@ again.
|
||||
Values: 0 or 1.
|
||||
Default 0.
|
||||
|
||||
When this option is set to 1, NERDCommenterToggle will check all selected line,
|
||||
When this option is set to 1, NERDCommenterToggle will check all selected line,
|
||||
if there have oneline not be commented, then comment all lines.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
@@ -855,7 +855,7 @@ file by the following line >
|
||||
<
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
3.3 Default delimiter customisation *NERDCommenterDefaultDelims*
|
||||
4.3 Default delimiter customisation *NERDCommenterDefaultDelims*
|
||||
|
||||
If you want the NERD commenter to use the alternative delimiters for a
|
||||
specific filetype by default then put a line of this form into your vimrc: >
|
||||
@@ -901,15 +901,15 @@ NERDComment({mode}, {type}) *NERDComment()*
|
||||
{mode}: character indicating the mode in which the comment
|
||||
is requested:
|
||||
'n' for Normal mode, 'x' for Visual mode
|
||||
{type}: the type of commenting requested. Can be 'Sexy',
|
||||
'Invert', 'Minimal', 'Toggle', 'AlignLeft',
|
||||
{type}: the type of commenting requested. Can be 'Sexy',
|
||||
'Invert', 'Minimal', 'Toggle', 'AlignLeft',
|
||||
'AlignBoth', 'Comment', 'Nested', 'ToEOL', 'Append',
|
||||
'Insert', 'Uncomment', 'Yank'
|
||||
|
||||
|
||||
NERDCommentIsCharCommented({line}, {col}) *NERDCommentIsCharCommented()*
|
||||
Check if the character at [{line}, {col}] is inside a comment
|
||||
Note the Comment delimeter it self is considered as part of the
|
||||
Note the Comment delimeter it self is considered as part of the
|
||||
comment
|
||||
|
||||
Args:
|
||||
|
||||
@@ -125,7 +125,7 @@ function! NERDCommentIsCharCommented(line, col)
|
||||
return nerdcommenter#IsCharCommented(a:line, a:col)
|
||||
endfunction
|
||||
|
||||
inoremap <silent> <Plug>NERDCommenterInsert <Space><BS><Esc>:call nerdcommenter#Comment('i', "insert")<CR>
|
||||
inoremap <silent> <Plug>NERDCommenterInsert <C-\><C-O>:call nerdcommenter#Comment('i', "Insert")<CR>
|
||||
|
||||
" switch to/from alternative delimiters (does not use wrapper function)
|
||||
nnoremap <Plug>NERDCommenterAltDelims :call nerdcommenter#SwitchToAlternativeDelimiters(1)<CR>
|
||||
|
||||
Reference in New Issue
Block a user