blob: 2c883a537a42084bf66826699c40a492c492f7c1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin
dkearns04e53632024-04-11 06:18:37 +10002" Language: Vim
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
Doug Kearns7ceaa8f2025-01-06 18:12:11 +01004" Last Change: 2025 Jan 06
Christian Brabandte978b452023-08-13 10:33:05 +02005" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Doug Kearnsfc61cfd2025-01-03 10:28:09 +01006" Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8" Only do this when not done yet for this buffer
9if exists("b:did_ftplugin")
10 finish
11endif
12
13" Don't load another plugin for this buffer
14let b:did_ftplugin = 1
15
Bram Moolenaar5c736222010-01-06 20:54:52 +010016let s:cpo_save = &cpo
Bram Moolenaar388a5d42020-05-26 21:20:45 +020017set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000018
Bram Moolenaarfd358112018-07-07 23:21:31 +020019if !exists('*VimFtpluginUndo')
20 func VimFtpluginUndo()
Bram Moolenaar5ed11532022-07-06 13:18:11 +010021 setl fo< isk< com< tw< commentstring< include< define<
Bram Moolenaard473c8c2018-08-11 18:00:22 +020022 if exists('b:did_add_maps')
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> ]"
33 silent! nunmap <buffer> ["
34 silent! vunmap <buffer> ["
Bram Moolenaarfd358112018-07-07 23:21:31 +020035 endif
36 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
37 endfunc
38endif
39
40let b:undo_ftplugin = "call VimFtpluginUndo()"
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
42" Set 'formatoptions' to break comment lines but not other lines,
43" and insert the comment leader when hitting <CR> or using "o".
44setlocal fo-=t fo+=croql
45
Bram Moolenaar5c736222010-01-06 20:54:52 +010046" To allow tag lookup via CTRL-] for autoload functions, '#' must be a
47" keyword character. E.g., for netrw#Nread().
48setlocal isk+=#
49
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +010050" Use :help to lookup the keyword under the cursor with K.
51setlocal keywordprg=:help
52
Bram Moolenaar71b6d332022-09-10 13:13:14 +010053" Comments starts with # in Vim9 script. We have to guess which one to use.
dkearns04e53632024-04-11 06:18:37 +100054if "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>'
Riley Bruins0a083062024-06-03 20:40:45 +020055 setlocal commentstring=#\ %s
Bram Moolenaar82be4842021-01-11 19:40:15 +010056else
Bram Moolenaar98a29d02021-01-18 19:55:44 +010057 setlocal commentstring=\"%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010058endif
59
Bram Moolenaar71b6d332022-09-10 13:13:14 +010060" Set 'comments' to format dashed lists in comments, both in Vim9 and legacy
61" script.
dkearns21ce1592024-01-29 04:54:08 +110062setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\"
Bram Moolenaar71b6d332022-09-10 13:13:14 +010063
Bram Moolenaar5ed11532022-07-06 13:18:11 +010064" set 'include' to recognize import commands
65setlocal include=\\v^\\s*import\\s*(autoload)?
66
67" set 'define' to recognize export commands
68setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)
Bram Moolenaar071d4272004-06-13 20:20:40 +000069
70" Format comments to be up to 78 characters long
71if &tw == 0
72 setlocal tw=78
73endif
74
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010075if !exists("no_plugin_maps") && !exists("no_vim_maps")
Bram Moolenaarfd358112018-07-07 23:21:31 +020076 let b:did_add_maps = 1
77
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010078 " Move around functions.
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010079 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
80 vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
81 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
82 vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
83 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
84 vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
85 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
86 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 +000087
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010088 " Move around comments
dkearnsfea96c02023-10-24 03:16:44 +110089 nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
90 vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010091 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
92 vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
93endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
95" Let the matchit plugin know what items can be matched.
96if exists("loaded_matchit")
97 let b:match_ignorecase = 0
Bram Moolenaare0e39172021-01-25 21:14:57 +010098 " "func" can also be used as a type:
99 " var Ref: func
100 " or to list functions:
101 " func name
102 " require a parenthesis following, then there can be an "endfunc".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103 let b:match_words =
Bram Moolenaar938ae282023-02-20 20:44:55 +0000104 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' ..
105 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' ..
106 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' ..
107 \ '{:},' ..
108 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' ..
109 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' ..
110 \ '\<class\>:\<endclass\>,' ..
Doug Kearnsfc61cfd2025-01-03 10:28:09 +0100111 \ '\<interface\>:\<endinterface\>,' ..
Doug Kearns7ceaa8f2025-01-06 18:12:11 +0100112 \ '\<enum\>:\<endenum\>'
Bram Moolenaar938ae282023-02-20 20:44:55 +0000113
Bram Moolenaar6e932462014-09-09 18:48:09 +0200114 " Ignore syntax region commands and settings, any 'en*' would clobber
115 " if-endif.
116 " - set spl=de,en
117 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/
Bram Moolenaar938ae282023-02-20 20:44:55 +0000118 " Also ignore here-doc and dictionary keys (vimVar).
119 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
120 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121endif
122
Bram Moolenaar5c736222010-01-06 20:54:52 +0100123let &cpo = s:cpo_save
124unlet s:cpo_save
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000125
126" removed this, because 'cpoptions' is a global option.
127" setlocal cpo+=M " makes \%( match \)