diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 19:06:15 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 19:06:15 +0000 |
commit | 8a66eac86090fec9b57bec1af185fc146e4ef63c (patch) | |
tree | 443889a4177a0003057d2dcb7005ceb97d8cb9cc /runtime/pack/dist/opt/comment | |
parent | Adding debian version 2:9.1.0374-1. (diff) | |
download | vim-8a66eac86090fec9b57bec1af185fc146e4ef63c.tar.xz vim-8a66eac86090fec9b57bec1af185fc146e4ef63c.zip |
Merging upstream version 2:9.1.0377.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'runtime/pack/dist/opt/comment')
-rw-r--r-- | runtime/pack/dist/opt/comment/autoload/comment.vim | 58 | ||||
-rw-r--r-- | runtime/pack/dist/opt/comment/doc/comment.txt | 59 | ||||
-rw-r--r-- | runtime/pack/dist/opt/comment/plugin/comment.vim | 9 |
3 files changed, 126 insertions, 0 deletions
diff --git a/runtime/pack/dist/opt/comment/autoload/comment.vim b/runtime/pack/dist/opt/comment/autoload/comment.vim new file mode 100644 index 0000000..9dda266 --- /dev/null +++ b/runtime/pack/dist/opt/comment/autoload/comment.vim @@ -0,0 +1,58 @@ +vim9script + +# Maintainer: Maxim Kim <habamax@gmail.com> +# Last Update: 2024-04-26 +# +# Toggle comments +# Usage: +# Add following mappings to vimrc: +# import autoload 'dist/comment.vim' +# nnoremap <silent> <expr> gc comment.Toggle() +# xnoremap <silent> <expr> gc comment.Toggle() +# nnoremap <silent> <expr> gcc comment.Toggle() .. '_' +export def Toggle(...args: list<string>): string + if len(args) == 0 + &opfunc = matchstr(expand('<stack>'), '[^. ]*\ze[') + return 'g@' + endif + if empty(&cms) || !&ma | return '' | endif + var cms = substitute(substitute(&cms, '\S\zs%s\s*', ' %s', ''), '%s\ze\S', '%s ', '') + var [lnum1, lnum2] = [line("'["), line("']")] + var cms_l = split(escape(cms, '*.'), '\s*%s\s*') + if len(cms_l) == 0 | return '' | endif + if len(cms_l) == 1 | call add(cms_l, '') | endif + var comment = 0 + var indent_min = indent(lnum1) + var indent_start = matchstr(getline(lnum1), '^\s*') + for lnum in range(lnum1, lnum2) + if getline(lnum) =~ '^\s*$' | continue | endif + if indent_min > indent(lnum) + indent_min = indent(lnum) + indent_start = matchstr(getline(lnum), '^\s*') + endif + if getline(lnum) !~ $'^\s*{cms_l[0]}.*{cms_l[1]}$' + comment = 1 + endif + endfor + var lines = [] + var line = '' + for lnum in range(lnum1, lnum2) + if getline(lnum) =~ '^\s*$' + line = getline(lnum) + elseif comment + if exists("g:comment_first_col") || exists("b:comment_first_col") + # handle % with substitute + line = printf(substitute(cms, '%s\@!', '%%', 'g'), getline(lnum)) + else + # handle % with substitute + line = printf(indent_start .. substitute(cms, '%s\@!', '%%', 'g'), + strpart(getline(lnum), strlen(indent_start))) + endif + else + line = substitute(getline(lnum), $'^\s*\zs{cms_l[0]} \?\| \?{cms_l[1]}$', '', 'g') + endif + add(lines, line) + endfor + noautocmd keepjumps setline(lnum1, lines) + return '' +enddef diff --git a/runtime/pack/dist/opt/comment/doc/comment.txt b/runtime/pack/dist/opt/comment/doc/comment.txt new file mode 100644 index 0000000..e2bf755 --- /dev/null +++ b/runtime/pack/dist/opt/comment/doc/comment.txt @@ -0,0 +1,59 @@ +*comment.txt* For Vim version 9.1. Last change: 2024 Apr 26 + + + VIM REFERENCE MANUAL + +Commenting and un-commenting text. + +============================================================================== + +The comment.vim package, allows to toggle comments for a single line, a range +of lines or a selected text object. It defines the following mappings: + + *gcc* +gcc to comment/uncomment current line + *o_gc* +gc{motion} to toggle comments for the selected motion + *gcip* +gcip to comment/uncomment current paragraph + *gcG* +gcG to comment/uncomment from current line till the end of a buffer + *v_gc* +{Visual}gc to comment/uncomment the highlighted lines. + +The plugin uses the buffer-local 'commentstring' option value to add or remove +comment markers to the selected lines. Whether it will comment or un-comment +depends on the first line of the range of lines to act upon. When it matches +a comment marker, the line will be un-commented, if it doesn't, the line will +be commented out. Blank and empty lines are not touched. + +If the mapping does not seem to work, chances are high, that this particular +filetype is either not detected by Vim or the filetype plugin does not set the +'commentstring' option. + +You can simply configure this using the following autocommand (e.g. for legacy +Vim script): > + + autocmd Filetype vim :setlocal commentstring="\ %s + +This example sets the " as start of a comment for legacy Vim Script. For Vim9 +script, you would instead use the "#" char: > + + autocmd Filetype vim :setlocal commentstring=#\ %s + +============================================================================== +Options: + +*g:comment_first_col* +*b:comment_first_col* + By default comment chars are added in front of the line, i.e. if the line + was indented, commented line would stay indented as well. + + However some filetypes require a comment char on the first column, use this option + to change default behaviour. + + Use g:comment_first_col to change it globally or b:comment_first_col to + target specific filetype(s). + +============================================================================== +vim:tw=78:ts=8:fo=tcq2:ft=help: diff --git a/runtime/pack/dist/opt/comment/plugin/comment.vim b/runtime/pack/dist/opt/comment/plugin/comment.vim new file mode 100644 index 0000000..94ac067 --- /dev/null +++ b/runtime/pack/dist/opt/comment/plugin/comment.vim @@ -0,0 +1,9 @@ +vim9script + +# Maintainer: Maxim Kim <habamax@gmail.com> +# Last Update: 2024-04-26 + +import autoload 'comment.vim' +nnoremap <silent> <expr> gc comment.Toggle() +xnoremap <silent> <expr> gc comment.Toggle() +nnoremap <silent> <expr> gcc comment.Toggle() .. '_' |