vim.vim (7092B)
1 " Vim filetype plugin 2 " Language: Vim 3 " Maintainer: Doug Kearns <dougkearns@gmail.com> 4 " Former Maintainer: Bram Moolenaar <Bram@vim.org> 5 " Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring') 6 " @Konfekt 7 " @tpope (s:Help()) 8 " Last Change: 2025 Aug 07 9 " 2025 Aug 16 by Vim Project set com depending on Vim9 or legacy script 10 " 2026 Jan 26 by Vim Project set path to common Vim directories #19219 11 " 2026 Feb 03 by Vim Project update s:Help to improve detecting functions #19320 12 13 " Only do this when not done yet for this buffer 14 if exists("b:did_ftplugin") 15 finish 16 endif 17 18 " Don't load another plugin for this buffer 19 let b:did_ftplugin = 1 20 21 let s:cpo_save = &cpo 22 set cpo&vim 23 24 if !exists('*VimFtpluginUndo') 25 func VimFtpluginUndo() 26 setl fo< isk< com< tw< commentstring< keywordprg< path< 27 sil! delc -buffer VimKeywordPrg 28 if exists('b:did_add_maps') 29 silent! nunmap <buffer> [[ 30 silent! xunmap <buffer> [[ 31 silent! nunmap <buffer> ]] 32 silent! xunmap <buffer> ]] 33 silent! nunmap <buffer> [] 34 silent! xunmap <buffer> [] 35 silent! nunmap <buffer> ][ 36 silent! xunmap <buffer> ][ 37 silent! nunmap <buffer> ]" 38 silent! xunmap <buffer> ]" 39 silent! nunmap <buffer> [" 40 silent! xunmap <buffer> [" 41 endif 42 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps 43 endfunc 44 endif 45 46 let b:undo_ftplugin = "call VimFtpluginUndo()" 47 48 " Set 'formatoptions' to break comment lines but not other lines, 49 " and insert the comment leader when hitting <CR> or using "o". 50 setlocal fo-=t fo+=croql 51 52 " To allow tag lookup via CTRL-] for autoload functions, '#' must be a 53 " keyword character. E.g., for netrw#Nread(). 54 setlocal isk+=# 55 56 " Use :help to lookup the keyword under the cursor with K. 57 " Distinguish between commands, options and functions. 58 if !exists("*" .. expand("<SID>") .. "Help") 59 function s:Help(topic) abort 60 let topic = a:topic 61 62 " keyword is not necessarily under the cursor, see :help K 63 let line = getline('.') 64 let i = match(line, '\V' .. escape(topic, '\'), col('.') - len(topic)) 65 let pre = strpart(line, 0, i) 66 let post = strpart(line, i + len(topic)) 67 68 " local/global option vars 69 if topic =~# '[lg]' && pre ==# '&' && post =~# ':\k\+' 70 let topic = matchstr(post, '\k\+') 71 endif 72 73 if get(g:, 'syntax_on', 0) 74 let syn = synIDattr(synID(line('.'), col('.'), 1), 'name') 75 if syn ==# 'vimFuncName' 76 return topic .. '()' 77 elseif syn ==# 'vimOption' || syn ==# 'vimOptionVarName' 78 return "'" .. topic .. "'" 79 elseif syn ==# 'vimUserCmdAttrKey' 80 return ':command-' .. topic 81 elseif syn ==# 'vimCommand' 82 return ':' .. topic 83 endif 84 endif 85 86 if stridx(post, '(') == 0 87 return topic .. '()' 88 elseif pre =~# '^\s*:\=$' || pre =~# '\%(\\\||\)\@<!|\s*:\=$' 89 return ':' .. topic 90 elseif pre =~# '\<v:$' 91 return 'v:' .. topic 92 elseif pre =~# '<$' 93 return '<' .. topic .. '>' 94 elseif pre =~# '\\$' 95 return '/\' .. topic 96 elseif topic ==# 'v' && post =~# ':\w\+' 97 return 'v' .. matchstr(post, ':\w\+') 98 elseif pre =~# '&\%([lg]:\)\=$' 99 return "'" .. topic .. "'" 100 else 101 return topic 102 endif 103 endfunction 104 endif 105 command! -buffer -nargs=1 VimKeywordPrg :exe 'help' s:Help(<q-args>) 106 setlocal keywordprg=:VimKeywordPrg 107 108 " Comments starts with # in Vim9 script. We have to guess which one to use. 109 if "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>' 110 setlocal commentstring=#\ %s 111 " Set 'comments' to format dashed lists in comments, for Vim9 script. 112 setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:# 113 else 114 setlocal commentstring=\"%s 115 " Set 'comments' to format dashed lists in comments, for legacy Vim script. 116 setlocal com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\" 117 endif 118 119 120 " Format comments to be up to 78 characters long 121 if &tw == 0 122 setlocal tw=78 123 endif 124 125 " set 'path' to common Vim directories 126 setlocal path-=/usr/include 127 setlocal path+=pack/**,runtime/**,autoload/**,colors/**,compiler/**,ftplugin/**,indent/**,keymap/**,macros/**,plugin/**,syntax/**,after/** 128 129 if !exists("no_plugin_maps") && !exists("no_vim_maps") 130 let b:did_add_maps = 1 131 132 " Move around functions. 133 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR> 134 xnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR> 135 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR> 136 xnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR> 137 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR> 138 xnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR> 139 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR> 140 xnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR> 141 142 " Move around comments 143 nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR> 144 xnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR> 145 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> 146 xnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> 147 endif 148 149 " Let the matchit plugin know what items can be matched. 150 if exists("loaded_matchit") 151 let b:match_ignorecase = 0 152 " "func" can also be used as a type: 153 " var Ref: func 154 " or to list functions: 155 " func name 156 " require a parenthesis following, then there can be an "endfunc". 157 let b:match_words = 158 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' .. 159 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' .. 160 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' .. 161 \ '{:},' .. 162 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' .. 163 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' .. 164 \ '\<class\>:\<endclass\>,' .. 165 \ '\<interface\>:\<endinterface\>,' .. 166 \ '\<enum\>:\<endenum\>' 167 168 " Ignore syntax region commands and settings, any 'en*' would clobber 169 " if-endif. 170 " - set spl=de,en 171 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ … 172 " Also ignore here-doc and dictionary keys (vimVar). 173 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") 174 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"' 175 endif 176 177 let &cpo = s:cpo_save 178 unlet s:cpo_save 179 180 " removed this, because 'cpoptions' is a global option. 181 " setlocal cpo+=M " makes \%( match \) 182 " 183 " vim: sw=2 et