Mercurial > vim
annotate runtime/ftplugin/vim.vim @ 33638:2d44cd7117fb
runtime(vim): Update ftplugin - comment motions (#13412)
Commit: https://github.com/vim/vim/commit/fea96c00e55a71e3007907ff4f7ad513bb9ff0eb
Author: dkearns <dougkearns@gmail.com>
Date: Tue Oct 24 03:16:44 2023 +1100
runtime(vim): Update ftplugin - comment motions (https://github.com/vim/vim/issues/13412)
Fix the pattern used by comment-motion mappings to match the start of a
block comment.
Block-comment start lines were being ignored if the previous line
contained a double-quote character anywhere in the line. Line comments
should only be ignored if the previous line is a full-line comment and,
therefore, part of the current block comment.
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 23 Oct 2023 18:30:06 +0200 |
parents | 4027cefc2aab |
children | 60e1e94a1b0e |
rev | line source |
---|---|
7 | 1 " Vim filetype plugin |
2 " Language: Vim | |
32770
4027cefc2aab
Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents:
32004
diff
changeset
|
3 " Maintainer: The Vim Project <https://github.com/vim/vim> |
4027cefc2aab
Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents:
32004
diff
changeset
|
4 " Last Change: 2023 Aug 10 |
4027cefc2aab
Farewell to Bram and dedicate upcoming Vim 9.1 to him (#12749)
Christian Brabandt <cb@256bit.org>
parents:
32004
diff
changeset
|
5 " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
7 | 6 |
7 " Only do this when not done yet for this buffer | |
8 if exists("b:did_ftplugin") | |
9 finish | |
10 endif | |
11 | |
12 " Don't load another plugin for this buffer | |
13 let b:did_ftplugin = 1 | |
14 | |
2034 | 15 let s:cpo_save = &cpo |
20552 | 16 set cpo&vim |
7 | 17 |
14298
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
18 if !exists('*VimFtpluginUndo') |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
19 func VimFtpluginUndo() |
29403 | 20 setl fo< isk< com< tw< commentstring< include< define< |
14519 | 21 if exists('b:did_add_maps') |
22 silent! nunmap <buffer> [[ | |
23 silent! vunmap <buffer> [[ | |
24 silent! nunmap <buffer> ]] | |
25 silent! vunmap <buffer> ]] | |
26 silent! nunmap <buffer> [] | |
27 silent! vunmap <buffer> [] | |
28 silent! nunmap <buffer> ][ | |
29 silent! vunmap <buffer> ][ | |
30 silent! nunmap <buffer> ]" | |
31 silent! vunmap <buffer> ]" | |
32 silent! nunmap <buffer> [" | |
33 silent! vunmap <buffer> [" | |
14298
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
34 endif |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
35 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
36 endfunc |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
37 endif |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
38 |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
39 let b:undo_ftplugin = "call VimFtpluginUndo()" |
7 | 40 |
41 " Set 'formatoptions' to break comment lines but not other lines, | |
42 " and insert the comment leader when hitting <CR> or using "o". | |
43 setlocal fo-=t fo+=croql | |
44 | |
2034 | 45 " To allow tag lookup via CTRL-] for autoload functions, '#' must be a |
46 " keyword character. E.g., for netrw#Nread(). | |
47 setlocal isk+=# | |
48 | |
12826 | 49 " Use :help to lookup the keyword under the cursor with K. |
50 setlocal keywordprg=:help | |
51 | |
30202 | 52 " Comments starts with # in Vim9 script. We have to guess which one to use. |
23573 | 53 if "\n" .. getline(1, 10)->join("\n") =~# '\n\s*vim9\%[script]\>' |
23666 | 54 setlocal commentstring=#%s |
23573 | 55 else |
23666 | 56 setlocal commentstring=\"%s |
23573 | 57 endif |
58 | |
30202 | 59 " Set 'comments' to format dashed lists in comments, both in Vim9 and legacy |
60 " script. | |
61 setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" | |
62 | |
29403 | 63 " set 'include' to recognize import commands |
64 setlocal include=\\v^\\s*import\\s*(autoload)? | |
65 | |
66 " set 'define' to recognize export commands | |
67 setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final) | |
7 | 68 |
69 " Format comments to be up to 78 characters long | |
70 if &tw == 0 | |
71 setlocal tw=78 | |
72 endif | |
73 | |
13051 | 74 if !exists("no_plugin_maps") && !exists("no_vim_maps") |
14298
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
75 let b:did_add_maps = 1 |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
76 |
13051 | 77 " Move around functions. |
30547 | 78 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> |
79 vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> | |
80 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR> | |
81 vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR> | |
82 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> | |
83 vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> | |
84 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR> | |
85 vnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR> | |
7 | 86 |
13051 | 87 " Move around comments |
33638
2d44cd7117fb
runtime(vim): Update ftplugin - comment motions (#13412)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
88 nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR> |
2d44cd7117fb
runtime(vim): Update ftplugin - comment motions (#13412)
Christian Brabandt <cb@256bit.org>
parents:
32770
diff
changeset
|
89 vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR> |
13051 | 90 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> |
91 vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> | |
92 endif | |
7 | 93 |
94 " Let the matchit plugin know what items can be matched. | |
95 if exists("loaded_matchit") | |
96 let b:match_ignorecase = 0 | |
23737 | 97 " "func" can also be used as a type: |
98 " var Ref: func | |
99 " or to list functions: | |
100 " func name | |
101 " require a parenthesis following, then there can be an "endfunc". | |
7 | 102 let b:match_words = |
32004 | 103 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' .. |
104 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' .. | |
105 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' .. | |
106 \ '{:},' .. | |
107 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' .. | |
108 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' .. | |
109 \ '\<class\>:\<endclass\>,' .. | |
110 \ '\<inte\%[rface]\>:\<endinterface\>,' .. | |
111 \ '\<enu\%[m]\>:\<endenum\>,' | |
112 | |
6213 | 113 " Ignore syntax region commands and settings, any 'en*' would clobber |
114 " if-endif. | |
115 " - set spl=de,en | |
116 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ … | |
32004 | 117 " Also ignore here-doc and dictionary keys (vimVar). |
118 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") | |
119 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"' | |
7 | 120 endif |
121 | |
2034 | 122 let &cpo = s:cpo_save |
123 unlet s:cpo_save | |
168 | 124 |
125 " removed this, because 'cpoptions' is a global option. | |
126 " setlocal cpo+=M " makes \%( match \) |