vim.vim (8657B)
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 " @lacygoill 9 " Last Change: 2026 Jun 27 10 " 2026 Aug 02 by Vim project: Update 'path' setting #20908 11 12 " Only do this when not done yet for this buffer 13 if exists("b:did_ftplugin") 14 finish 15 endif 16 17 " Don't load another plugin for this buffer 18 let b:did_ftplugin = 1 19 20 let s:cpo_save = &cpo 21 set cpo&vim 22 23 if !exists('*VimFtpluginUndo') 24 func VimFtpluginUndo() 25 setl fo< isk< com< tw< commentstring< include< define< keywordprg< omnifunc< path< 26 sil! delc -buffer VimKeywordPrg 27 if exists('b:did_add_maps') 28 silent! nunmap <buffer> [[ 29 silent! xunmap <buffer> [[ 30 silent! nunmap <buffer> ]] 31 silent! xunmap <buffer> ]] 32 silent! nunmap <buffer> [] 33 silent! xunmap <buffer> [] 34 silent! nunmap <buffer> ][ 35 silent! xunmap <buffer> ][ 36 silent! nunmap <buffer> ]" 37 silent! xunmap <buffer> ]" 38 silent! nunmap <buffer> [" 39 silent! xunmap <buffer> [" 40 silent! nunmap <buffer> gf 41 silent! nunmap <buffer> <C-W>f 42 silent! nunmap <buffer> <C-W>gf 43 endif 44 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps 45 endfunc 46 endif 47 48 let b:undo_ftplugin = "call VimFtpluginUndo()" 49 50 " Set 'formatoptions' to break comment lines but not other lines, 51 " and insert the comment leader when hitting <CR> or using "o". 52 setlocal fo-=t fo+=croql 53 54 " To allow tag lookup via CTRL-] for autoload functions, '#' must be a 55 " keyword character. E.g., for netrw#Nread(). 56 setlocal isk+=# 57 58 " Use :help to lookup the keyword under the cursor with K. 59 " Distinguish between commands, options and functions. 60 if !exists("*" .. expand("<SID>") .. "Help") 61 function s:Help(topic) abort 62 let topic = a:topic 63 64 " keyword is not necessarily under the cursor, see :help K 65 let line = getline('.') 66 let i = match(line, '\V' .. escape(topic, '\'), col('.') - len(topic)) 67 let pre = strpart(line, 0, i) 68 let post = strpart(line, i + len(topic)) 69 70 " local/global option vars 71 if topic =~# '[lg]' && pre ==# '&' && post =~# ':\k\+' 72 let topic = matchstr(post, '\k\+') 73 endif 74 75 if get(g:, 'syntax_on', 0) 76 let syn = synIDattr(synID(line('.'), col('.'), 1), 'name') 77 if syn ==# 'vimFuncName' 78 return topic .. '()' 79 elseif syn ==# 'vimOption' || syn ==# 'vimOptionVarName' 80 return "'" .. topic .. "'" 81 elseif syn ==# 'vimUserCmdAttrKey' 82 return ':command-' .. topic 83 elseif syn ==# 'vimCommand' 84 return ':' .. topic 85 endif 86 endif 87 88 if stridx(post, '(') == 0 89 return topic .. '()' 90 elseif pre =~# '^\s*:\=$' || pre =~# '\%(\\\||\)\@<!|\s*:\=$' 91 return ':' .. topic 92 elseif pre =~# '\<v:$' 93 return 'v:' .. topic 94 elseif pre =~# '<$' 95 return '<' .. topic .. '>' 96 elseif pre =~# '\\$' 97 return '/\' .. topic 98 elseif topic ==# 'v' && post =~# ':\w\+' 99 return 'v' .. matchstr(post, ':\w\+') 100 elseif pre =~# '&\%([lg]:\)\=$' 101 return "'" .. topic .. "'" 102 else 103 return topic 104 endif 105 endfunction 106 endif 107 command! -buffer -nargs=1 VimKeywordPrg :exe 'help' s:Help(<q-args>) 108 setlocal keywordprg=:VimKeywordPrg 109 110 " Comments starts with # in Vim9 script. We have to guess which one to use. 111 if "\n" .. getline(1, 32)->join("\n") =~# '\nvim9s\%[cript]\>' 112 setlocal commentstring=#\ %s 113 " Set 'comments' to format dashed lists in comments, for Vim9 script. 114 setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:# 115 else 116 setlocal commentstring=\"%s 117 " Set 'comments' to format dashed lists in comments, for legacy Vim script. 118 setlocal com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\" 119 endif 120 121 " set 'include' to recognize import commands 122 setlocal include=\\v^\\s*import\\s*(autoload)? 123 124 " set 'define' to recognize export commands 125 setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final) 126 127 if has("vim9script") 128 " set omnifunc completion 129 setlocal omnifunc=vimcomplete#Complete 130 endif 131 132 " Format comments to be up to 78 characters long 133 if &tw == 0 134 setlocal tw=78 135 endif 136 137 " set 'path' to common Vim directories 138 setlocal path-=/usr/include 139 setlocal path+=pack/**,runtime/**,autoload/**,colors/**,compiler/**,ftplugin/**,indent/**,keymap/**,macros/**,plugin/**,syntax/**,after/**,python/** 140 141 if !exists("no_plugin_maps") && !exists("no_vim_maps") 142 let b:did_add_maps = 1 143 144 " Move around functions. 145 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> 146 xnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> 147 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR> 148 xnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR> 149 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> 150 xnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR> 151 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR> 152 xnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR> 153 154 " Move around comments 155 nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR> 156 xnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR> 157 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> 158 xnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> 159 160 " Purpose: Handle :import, :colorscheme and :packadd lines in a smarter way. {{{ 161 " 162 " `:import` is followed by a filename or filepath. Find it. 163 " 164 " `:packadd` is followed by the name of a package, which we might have 165 " configured in scripts under `~/.vim/plugin`. Find it. 166 " 167 " --- 168 " 169 " We can't handle the `:import` lines simply by setting `'includeexpr'`, because 170 " the option would be ignored if: 171 " 172 " - the name of the imported script is the same as the current one 173 " - `'path'` includes the `.` item 174 " 175 " Indeed, in that case, Vim finds the current file, and simply reloads the 176 " buffer. 177 " }}} 178 " We use the `F` variants, instead of the `f` ones, because they're smarter. 179 " See $VIMRUNTIME/autoload/vimgoto.vim 180 nnoremap <silent><buffer> gf :<C-U>call vimgoto#Find('gF')<CR> 181 nnoremap <silent><buffer> <C-W>f :<C-U>call vimgoto#Find("\<lt>C-W>F")<CR> 182 nnoremap <silent><buffer> <C-W>gf :<C-U>call vimgoto#Find("\<lt>C-W>gF")<CR> 183 endif 184 185 " Let the matchit plugin know what items can be matched. 186 if exists("loaded_matchit") 187 let b:match_ignorecase = 0 188 " "func" can also be used as a type: 189 " var Ref: func 190 " or to list functions: 191 " func name 192 " require a parenthesis following, then there can be an "endfunc". 193 let b:match_words = 194 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' .. 195 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' .. 196 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' .. 197 \ '{:},' .. 198 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' .. 199 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' .. 200 \ '\<class\>:\<endclass\>,' .. 201 \ '\<interface\>:\<endinterface\>,' .. 202 \ '\<enum\>:\<endenum\>,' .. 203 "\ :let-heredoc 204 \ '\%(=<<\s\+\%(\%(trim\s\+eval\|eval\s\+trim\|trim\|eval\)\s\+\)\=\)\@16<=\(\l\@!\S\+\):\%(^\s*\)\@<=\1$' 205 206 " Ignore syntax region commands and settings, any 'en*' would clobber 207 " if-endif. 208 " - set spl=de,en 209 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ … 210 " Also ignore heredoc content and dictionary keys (vimVar). 211 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") 212 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHeredoc$\\|vimVar"' 213 endif 214 215 let &cpo = s:cpo_save 216 unlet s:cpo_save 217 218 " removed this, because 'cpoptions' is a global option. 219 " setlocal cpo+=M " makes \%( match \) 220 " 221 " vim: sw=2 et