blob: e25054ba89f95cbfb6273aba50d634fede8c7bed [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin
2" Language: Vim
Christian Brabandte978b452023-08-13 10:33:05 +02003" Maintainer: The Vim Project <https://github.com/vim/vim>
4" Last Change: 2023 Aug 10
5" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7" Only do this when not done yet for this buffer
8if exists("b:did_ftplugin")
9 finish
10endif
11
12" Don't load another plugin for this buffer
13let b:did_ftplugin = 1
14
Bram Moolenaar5c736222010-01-06 20:54:52 +010015let s:cpo_save = &cpo
Bram Moolenaar388a5d42020-05-26 21:20:45 +020016set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000017
Bram Moolenaarfd358112018-07-07 23:21:31 +020018if !exists('*VimFtpluginUndo')
19 func VimFtpluginUndo()
Bram Moolenaar5ed11532022-07-06 13:18:11 +010020 setl fo< isk< com< tw< commentstring< include< define<
Bram Moolenaard473c8c2018-08-11 18:00:22 +020021 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> ["
Bram Moolenaarfd358112018-07-07 23:21:31 +020034 endif
35 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
36 endfunc
37endif
38
39let b:undo_ftplugin = "call VimFtpluginUndo()"
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
41" Set 'formatoptions' to break comment lines but not other lines,
42" and insert the comment leader when hitting <CR> or using "o".
43setlocal fo-=t fo+=croql
44
Bram Moolenaar5c736222010-01-06 20:54:52 +010045" To allow tag lookup via CTRL-] for autoload functions, '#' must be a
46" keyword character. E.g., for netrw#Nread().
47setlocal isk+=#
48
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +010049" Use :help to lookup the keyword under the cursor with K.
50setlocal keywordprg=:help
51
Bram Moolenaar71b6d332022-09-10 13:13:14 +010052" Comments starts with # in Vim9 script. We have to guess which one to use.
Bram Moolenaar82be4842021-01-11 19:40:15 +010053if "\n" .. getline(1, 10)->join("\n") =~# '\n\s*vim9\%[script]\>'
Bram Moolenaar98a29d02021-01-18 19:55:44 +010054 setlocal commentstring=#%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010055else
Bram Moolenaar98a29d02021-01-18 19:55:44 +010056 setlocal commentstring=\"%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010057endif
58
Bram Moolenaar71b6d332022-09-10 13:13:14 +010059" Set 'comments' to format dashed lists in comments, both in Vim9 and legacy
60" script.
61setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"
62
Bram Moolenaar5ed11532022-07-06 13:18:11 +010063" set 'include' to recognize import commands
64setlocal include=\\v^\\s*import\\s*(autoload)?
65
66" set 'define' to recognize export commands
67setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)
Bram Moolenaar071d4272004-06-13 20:20:40 +000068
69" Format comments to be up to 78 characters long
70if &tw == 0
71 setlocal tw=78
72endif
73
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010074if !exists("no_plugin_maps") && !exists("no_vim_maps")
Bram Moolenaarfd358112018-07-07 23:21:31 +020075 let b:did_add_maps = 1
76
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010077 " Move around functions.
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010078 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>
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010087 " Move around comments
88 nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
89 vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
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>
92endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
94" Let the matchit plugin know what items can be matched.
95if exists("loaded_matchit")
96 let b:match_ignorecase = 0
Bram Moolenaare0e39172021-01-25 21:14:57 +010097 " "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".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102 let b:match_words =
Bram Moolenaar938ae282023-02-20 20:44:55 +0000103 \ '\<\%(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
Bram Moolenaar6e932462014-09-09 18:48:09 +0200113 " 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=/}/
Bram Moolenaar938ae282023-02-20 20:44:55 +0000117 " 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"'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120endif
121
Bram Moolenaar5c736222010-01-06 20:54:52 +0100122let &cpo = s:cpo_save
123unlet s:cpo_save
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000124
125" removed this, because 'cpoptions' is a global option.
126" setlocal cpo+=M " makes \%( match \)