blob: e28beb9848abf920037f33304a0feea46e3ae640 [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>
4" Last Change: 2024 Apr 08
Christian Brabandte978b452023-08-13 10:33:05 +02005" 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
Wu, Zhenyufcbefe72024-04-11 21:25:39 +020018compiler vimdoc
19
Bram Moolenaarfd358112018-07-07 23:21:31 +020020if !exists('*VimFtpluginUndo')
21 func VimFtpluginUndo()
Bram Moolenaar5ed11532022-07-06 13:18:11 +010022 setl fo< isk< com< tw< commentstring< include< define<
Bram Moolenaard473c8c2018-08-11 18:00:22 +020023 if exists('b:did_add_maps')
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> ]"
34 silent! nunmap <buffer> ["
35 silent! vunmap <buffer> ["
Bram Moolenaarfd358112018-07-07 23:21:31 +020036 endif
37 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
38 endfunc
39endif
40
41let b:undo_ftplugin = "call VimFtpluginUndo()"
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
43" Set 'formatoptions' to break comment lines but not other lines,
44" and insert the comment leader when hitting <CR> or using "o".
45setlocal fo-=t fo+=croql
46
Bram Moolenaar5c736222010-01-06 20:54:52 +010047" To allow tag lookup via CTRL-] for autoload functions, '#' must be a
48" keyword character. E.g., for netrw#Nread().
49setlocal isk+=#
50
Bram Moolenaar7f2e9d72017-11-11 20:58:53 +010051" Use :help to lookup the keyword under the cursor with K.
52setlocal keywordprg=:help
53
Bram Moolenaar71b6d332022-09-10 13:13:14 +010054" Comments starts with # in Vim9 script. We have to guess which one to use.
dkearns04e53632024-04-11 06:18:37 +100055if "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>'
Bram Moolenaar98a29d02021-01-18 19:55:44 +010056 setlocal commentstring=#%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010057else
Bram Moolenaar98a29d02021-01-18 19:55:44 +010058 setlocal commentstring=\"%s
Bram Moolenaar82be4842021-01-11 19:40:15 +010059endif
60
Bram Moolenaar71b6d332022-09-10 13:13:14 +010061" Set 'comments' to format dashed lists in comments, both in Vim9 and legacy
62" script.
dkearns21ce1592024-01-29 04:54:08 +110063setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\"
Bram Moolenaar71b6d332022-09-10 13:13:14 +010064
Bram Moolenaar5ed11532022-07-06 13:18:11 +010065" set 'include' to recognize import commands
66setlocal include=\\v^\\s*import\\s*(autoload)?
67
68" set 'define' to recognize export commands
69setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)
Bram Moolenaar071d4272004-06-13 20:20:40 +000070
71" Format comments to be up to 78 characters long
72if &tw == 0
73 setlocal tw=78
74endif
75
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010076if !exists("no_plugin_maps") && !exists("no_vim_maps")
Bram Moolenaarfd358112018-07-07 23:21:31 +020077 let b:did_add_maps = 1
78
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010079 " Move around functions.
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010080 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
81 vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
82 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
83 vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
84 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
85 vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
86 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
87 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 +000088
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010089 " Move around comments
dkearnsfea96c02023-10-24 03:16:44 +110090 nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
91 vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010092 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
93 vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
94endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96" Let the matchit plugin know what items can be matched.
97if exists("loaded_matchit")
98 let b:match_ignorecase = 0
Bram Moolenaare0e39172021-01-25 21:14:57 +010099 " "func" can also be used as a type:
100 " var Ref: func
101 " or to list functions:
102 " func name
103 " require a parenthesis following, then there can be an "endfunc".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104 let b:match_words =
Bram Moolenaar938ae282023-02-20 20:44:55 +0000105 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' ..
106 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' ..
107 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' ..
108 \ '{:},' ..
109 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' ..
110 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' ..
111 \ '\<class\>:\<endclass\>,' ..
112 \ '\<inte\%[rface]\>:\<endinterface\>,' ..
113 \ '\<enu\%[m]\>:\<endenum\>,'
114
Bram Moolenaar6e932462014-09-09 18:48:09 +0200115 " Ignore syntax region commands and settings, any 'en*' would clobber
116 " if-endif.
117 " - set spl=de,en
118 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/
Bram Moolenaar938ae282023-02-20 20:44:55 +0000119 " Also ignore here-doc and dictionary keys (vimVar).
120 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
121 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122endif
123
Bram Moolenaar5c736222010-01-06 20:54:52 +0100124let &cpo = s:cpo_save
125unlet s:cpo_save
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000126
127" removed this, because 'cpoptions' is a global option.
128" setlocal cpo+=M " makes \%( match \)