codekingpro/portable-devtools
114k
1" Vim filetype plugin2" Language: Vim3" Maintainer: Doug Kearns <dougkearns@gmail.com>4" Former Maintainer: Bram Moolenaar <Bram@vim.org>5" Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring')6" @Konfekt7" @tpope (s:Help())8" @lacygoill9" Last Change: 2025 Aug 0710" 2025 Aug 06 by Vim Project (add gf maps #17881)11" 2025 Aug 08 by Vim Project (add Vim script complete function #17871)12" 2025 Aug 12 by Vim Project (improve vimgoto script #17970))13" 2025 Aug 16 by Vim Project set com depending on Vim9 or legacy script14" 2026 Jan 26 by Vim Project set path to common Vim directories #1921915" 2026 Feb 03 by Vim Project update s:Help to improve detecting functions #1932016 17" Only do this when not done yet for this buffer18if exists("b:did_ftplugin")19 finish20endif21 22" Don't load another plugin for this buffer23let b:did_ftplugin = 124 25let s:cpo_save = &cpo26set cpo&vim27 28if !exists('*VimFtpluginUndo')29 func VimFtpluginUndo()30 setl fo< isk< com< tw< commentstring< include< define< keywordprg< omnifunc< path<31 sil! delc -buffer VimKeywordPrg32 if exists('b:did_add_maps')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 silent! nunmap <buffer> ]"42 silent! xunmap <buffer> ]"43 silent! nunmap <buffer> ["44 silent! xunmap <buffer> ["45 silent! nunmap <buffer> gf46 silent! nunmap <buffer> <C-W>f47 silent! nunmap <buffer> <C-W>gf48 endif49 unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps50 endfunc51endif52 53let b:undo_ftplugin = "call VimFtpluginUndo()"54 55" Set 'formatoptions' to break comment lines but not other lines,56" and insert the comment leader when hitting <CR> or using "o".57setlocal fo-=t fo+=croql58 59" To allow tag lookup via CTRL-] for autoload functions, '#' must be a60" keyword character. E.g., for netrw#Nread().61setlocal isk+=#62 63" Use :help to lookup the keyword under the cursor with K.64" Distinguish between commands, options and functions.65if !exists("*" .. expand("<SID>") .. "Help")66 function s:Help(topic) abort67 let topic = a:topic68 69 " keyword is not necessarily under the cursor, see :help K70 let line = getline('.')71 let i = match(line, '\V' .. escape(topic, '\'), col('.') - len(topic))72 let pre = strpart(line, 0, i)73 let post = strpart(line, i + len(topic))74 75 " local/global option vars76 if topic =~# '[lg]' && pre ==# '&' && post =~# ':\k\+'77 let topic = matchstr(post, '\k\+')78 endif79 80 if get(g:, 'syntax_on', 0)81 let syn = synIDattr(synID(line('.'), col('.'), 1), 'name')82 if syn ==# 'vimFuncName'83 return topic .. '()'84 elseif syn ==# 'vimOption' || syn ==# 'vimOptionVarName'85 return "'" .. topic .. "'"86 elseif syn ==# 'vimUserCmdAttrKey'87 return ':command-' .. topic88 elseif syn ==# 'vimCommand'89 return ':' .. topic90 endif91 endif92 93 if stridx(post, '(') == 094 return topic .. '()'95 elseif pre =~# '^\s*:\=$' || pre =~# '\%(\\\||\)\@<!|\s*:\=$'96 return ':' .. topic97 elseif pre =~# '\<v:$'98 return 'v:' .. topic99 elseif pre =~# '<$'100 return '<' .. topic .. '>'101 elseif pre =~# '\\$'102 return '/\' .. topic103 elseif topic ==# 'v' && post =~# ':\w\+'104 return 'v' .. matchstr(post, ':\w\+')105 elseif pre =~# '&\%([lg]:\)\=$'106 return "'" .. topic .. "'"107 else108 return topic109 endif110 endfunction111endif112command! -buffer -nargs=1 VimKeywordPrg :exe 'help' s:Help(<q-args>)113setlocal keywordprg=:VimKeywordPrg114 115" Comments starts with # in Vim9 script. We have to guess which one to use.116if "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>'117 setlocal commentstring=#\ %s118 " Set 'comments' to format dashed lists in comments, for Vim9 script.119 setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:#120else121 setlocal commentstring=\"%s122 " Set 'comments' to format dashed lists in comments, for legacy Vim script.123 setlocal com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\"124endif125 126" set 'include' to recognize import commands127setlocal include=\\v^\\s*import\\s*(autoload)?128 129" set 'define' to recognize export commands130setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)131 132if has("vim9script")133 " set omnifunc completion134 setlocal omnifunc=vimcomplete#Complete135endif136 137" Format comments to be up to 78 characters long138if &tw == 0139 setlocal tw=78140endif141 142" set 'path' to common Vim directories143setlocal path-=/usr/include144setlocal path+=pack/**,runtime/**,autoload/**,colors/**,compiler/**,ftplugin/**,indent/**,keymap/**,macros/**,plugin/**,syntax/**,after/**145 146if !exists("no_plugin_maps") && !exists("no_vim_maps")147 let b:did_add_maps = 1148 149 " Move around functions.150 nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>151 xnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>152 nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>153 xnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>154 nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>155 xnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>156 nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>157 xnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>158 159 " Move around comments160 nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>161 xnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>162 nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>163 xnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>164 165 " Purpose: Handle :import, :colorscheme and :packadd lines in a smarter way. {{{166 "167 " `:import` is followed by a filename or filepath. Find it.168 "169 " `:packadd` is followed by the name of a package, which we might have170 " configured in scripts under `~/.vim/plugin`. Find it.171 "172 " ---173 "174 " We can't handle the `:import` lines simply by setting `'includeexpr'`, because175 " the option would be ignored if:176 "177 " - the name of the imported script is the same as the current one178 " - `'path'` includes the `.` item179 "180 " Indeed, in that case, Vim finds the current file, and simply reloads the181 " buffer.182 " }}}183 " We use the `F` variants, instead of the `f` ones, because they're smarter.184 " See $VIMRUNTIME/autoload/vimgoto.vim185 nnoremap <silent><buffer> gf :<C-U>call vimgoto#Find('gF')<CR>186 nnoremap <silent><buffer> <C-W>f :<C-U>call vimgoto#Find("\<lt>C-W>F")<CR>187 nnoremap <silent><buffer> <C-W>gf :<C-U>call vimgoto#Find("\<lt>C-W>gF")<CR>188endif189 190" Let the matchit plugin know what items can be matched.191if exists("loaded_matchit")192 let b:match_ignorecase = 0193 " "func" can also be used as a type:194 " var Ref: func195 " or to list functions:196 " func name197 " require a parenthesis following, then there can be an "endfunc".198 let b:match_words =199 \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' ..200 \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' ..201 \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' ..202 \ '{:},' ..203 \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' ..204 \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' ..205 \ '\<class\>:\<endclass\>,' ..206 \ '\<interface\>:\<endinterface\>,' ..207 \ '\<enum\>:\<endenum\>'208 209 " Ignore syntax region commands and settings, any 'en*' would clobber210 " if-endif.211 " - set spl=de,en212 " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ …213 " Also ignore here-doc and dictionary keys (vimVar).214 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")215 \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"'216endif217 218let &cpo = s:cpo_save219unlet s:cpo_save220 221" removed this, because 'cpoptions' is a global option.222" setlocal cpo+=M " makes \%( match \)223"224" vim: sw=2 et225 