blob: 1ae1d2346b9663f7ec722e2c54bdb9e48293cf39 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin
2" Language: Vim
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar938ae282023-02-20 20:44:55 +00004" Last Change: 2023 Feb 07
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6" Only do this when not done yet for this buffer
7if exists("b:did_ftplugin")
8 finish
9endif
10
11" Don't load another plugin for this buffer
12let b:did_ftplugin = 1
13
Bram Moolenaar5c736222010-01-06 20:54:52 +010014let s:cpo_save = &cpo
Bram Moolenaar388a5d42020-05-26 21:20:45 +020015set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000016
Bram Moolenaarfd358112018-07-07 23:21:31 +020017if !exists('*VimFtpluginUndo')
18 func VimFtpluginUndo()
Bram Moolenaar5ed11532022-07-06 13:18:11 +010019 setl fo< isk< com< tw< commentstring< include< define<
Bram Moolenaard473c8c2018-08-11 18:00:22 +020020 if exists('b:did_add_maps')
21 silent! nunmap <buffer> [[
22 silent! vunmap <buffer> [[
23 silent! nunmap <buffer> ]]
24 silent! vunmap <buffer> ]]
25 silent! nunmap <buffer> []
26 silent! vunmap <buffer> []
27 silent! nunmap <buffer> ][
28 silent! vunmap <buffer> ][
29 silent! nunmap <buffer> ]"
30 silent! vunmap <buffer> ]"
31 silent! nunmap <buffer> ["
32 silent! vunmap <buffer> ["
Bram Moolenaarfd358112018-07-07 23:21:31 +020033 endif
34 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
35 endfunc
36endif
37
38let b:undo_ftplugin = "call VimFtpluginUndo()"
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
40" Set 'formatoptions' to break comment lines but not other lines,
41" and insert the comment leader when hitting <CR> or using "o".
42setlocal fo-=t fo+=croql
43
Bram Moolenaar5c736222010-01-06 20:54:52 +010044" To allow tag lookup via CTRL-] for autoload functions, '#' must be a
45" keyword character. E.g., for netrw#Nread().
46setlocal isk+=#
47
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +010048" Use :help to lookup the keyword under the cursor with K.
49setlocal keywordprg=:help
50
Bram Moolenaar71b6d332022-09-10 13:13:14 +010051" Comments starts with # in Vim9 script. We have to guess which one to use.
Bram Moolenaar82be4842021-01-11 19:40:15 +010052if "\n" .. getline(1, 10)->join("\n") =~# '\n\s*vim9\%[script]\>'
Bram Moolenaar98a29d02021-01-18 19:55:44 +010053 setlocal commentstring=#%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010054else
Bram Moolenaar98a29d02021-01-18 19:55:44 +010055 setlocal commentstring=\"%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010056endif
57
Bram Moolenaar71b6d332022-09-10 13:13:14 +010058" Set 'comments' to format dashed lists in comments, both in Vim9 and legacy
59" script.
60setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"
61
Bram Moolenaar5ed11532022-07-06 13:18:11 +010062" set 'include' to recognize import commands
63setlocal include=\\v^\\s*import\\s*(autoload)?
64
65" set 'define' to recognize export commands
66setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
68" Format comments to be up to 78 characters long
69if &tw == 0
70 setlocal tw=78
71endif
72
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010073if !exists("no_plugin_maps") && !exists("no_vim_maps")
Bram Moolenaarfd358112018-07-07 23:21:31 +020074 let b:did_add_maps = 1
75
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010076 " Move around functions.
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010077 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
78 vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
79 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
80 vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
81 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
82 vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
83 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
84 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 +000085
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010086 " Move around comments
87 nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
88 vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
89 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
90 vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
91endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
93" Let the matchit plugin know what items can be matched.
94if exists("loaded_matchit")
95 let b:match_ignorecase = 0
Bram Moolenaare0e39172021-01-25 21:14:57 +010096 " "func" can also be used as a type:
97 " var Ref: func
98 " or to list functions:
99 " func name
100 " require a parenthesis following, then there can be an "endfunc".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101 let b:match_words =
Bram Moolenaar938ae282023-02-20 20:44:55 +0000102 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' ..
103 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' ..
104 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' ..
105 \ '{:},' ..
106 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' ..
107 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' ..
108 \ '\<class\>:\<endclass\>,' ..
109 \ '\<inte\%[rface]\>:\<endinterface\>,' ..
110 \ '\<enu\%[m]\>:\<endenum\>,'
111
Bram Moolenaar6e932462014-09-09 18:48:09 +0200112 " Ignore syntax region commands and settings, any 'en*' would clobber
113 " if-endif.
114 " - set spl=de,en
115 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/
Bram Moolenaar938ae282023-02-20 20:44:55 +0000116 " Also ignore here-doc and dictionary keys (vimVar).
117 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
118 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119endif
120
Bram Moolenaar5c736222010-01-06 20:54:52 +0100121let &cpo = s:cpo_save
122unlet s:cpo_save
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000123
124" removed this, because 'cpoptions' is a global option.
125" setlocal cpo+=M " makes \%( match \)