blob: b87e1442205349e7a62265283b4b5a1e5f9af989 [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 Moolenaar3d1cde82020-08-15 18:55:18 +02004" Last Change: 2020 Aug 14
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()
19 setl fo< isk< com< tw< commentstring<
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 Moolenaar071d4272004-06-13 20:20:40 +000051" Set 'comments' to format dashed lists in comments
Bram Moolenaar3d1cde82020-08-15 18:55:18 +020052" Avoid that #{} starts a comment.
53setlocal com=sO:\"\ -,mO:\"\ \ ,sO:#\ -,mO:#\ \ ,eO:##,:\",b:#
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
55" Format comments to be up to 78 characters long
56if &tw == 0
57 setlocal tw=78
58endif
59
Bram Moolenaar7ff78462020-07-10 22:00:53 +020060" Comments start with a double quote; in Vim9 script # would also work
Bram Moolenaar071d4272004-06-13 20:20:40 +000061setlocal commentstring=\"%s
62
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010063if !exists("no_plugin_maps") && !exists("no_vim_maps")
Bram Moolenaarfd358112018-07-07 23:21:31 +020064 let b:did_add_maps = 1
65
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010066 " Move around functions.
Bram Moolenaar388a5d42020-05-26 21:20:45 +020067 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR>
68 vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR>
69 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR>
70 vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR>
71 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR>
72 vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR>
73 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR>
74 vnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +000075
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010076 " Move around comments
77 nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
78 vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
79 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
80 vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
81endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000082
83" Let the matchit plugin know what items can be matched.
84if exists("loaded_matchit")
85 let b:match_ignorecase = 0
86 let b:match_words =
Bram Moolenaare7b1ea02020-08-07 19:54:59 +020087 \ '\<\%(fu\%[nction]\|def\)\>)\@!:\<retu\%[rn]\>:\<\%(endf\%[unction]\|enddef\)\>,' .
Bram Moolenaar5c736222010-01-06 20:54:52 +010088 \ '\<\(wh\%[ile]\|for\)\>:\<brea\%[k]\>:\<con\%[tinue]\>:\<end\(w\%[hile]\|fo\%[r]\)\>,' .
Bram Moolenaar071d4272004-06-13 20:20:40 +000089 \ '\<if\>:\<el\%[seif]\>:\<en\%[dif]\>,' .
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010090 \ '{:},' .
Bram Moolenaar071d4272004-06-13 20:20:40 +000091 \ '\<try\>:\<cat\%[ch]\>:\<fina\%[lly]\>:\<endt\%[ry]\>,' .
Bram Moolenaar93a1df22018-09-10 11:51:50 +020092 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,'
Bram Moolenaar6e932462014-09-09 18:48:09 +020093 " Ignore syntax region commands and settings, any 'en*' would clobber
94 " if-endif.
95 " - set spl=de,en
96 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ …
97 let b:match_skip = 'synIDattr(synID(line("."),col("."),1),"name")
98 \ =~? "comment\\|string\\|vimSynReg\\|vimSet"'
Bram Moolenaar071d4272004-06-13 20:20:40 +000099endif
100
Bram Moolenaar5c736222010-01-06 20:54:52 +0100101let &cpo = s:cpo_save
102unlet s:cpo_save
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000103
104" removed this, because 'cpoptions' is a global option.
105" setlocal cpo+=M " makes \%( match \)