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