robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40466 from zeertzjq/vim-06512b175749af288

master
6.9 KiB183 linesraw
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")
13  finish
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')
23  func VimFtpluginUndo()
24    setl fo< isk< com< tw< commentstring< keywordprg< path<
25    sil! delc -buffer VimKeywordPrg
26    if exists('b:did_add_maps')
27      silent! nunmap <buffer> [[
28      silent! xunmap <buffer> [[
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     endif
40    unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
41  endfunc
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-=t fo+=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")
57  function s:Help(topic) abort
58    let topic = a:topic
59
60    " keyword is not necessarily under the cursor, see :help K
61    let line = getline('.')
62    let i = match(line, '\V' .. escape(topic, '\'), col('.') - len(topic))
63    let pre = strpart(line, 0, i)
64    let post = strpart(line, i + len(topic))
65
66    " local/global option vars
67    if topic =~# '[lg]' && pre ==# '&' && post =~# ':\k\+'
68      let topic = matchstr(post, '\k\+')
69    endif
70
71    if get(g:, 'syntax_on', 0)
72      let syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
73      if syn ==# 'vimFuncName'
74        return topic .. '()'
75      elseif syn ==# 'vimOption' || syn ==# 'vimOptionVarName'
76        return "'" .. topic .. "'"
77      elseif syn ==# 'vimUserCmdAttrKey'
78        return ':command-' .. topic
79      elseif syn ==# 'vimCommand'
80        return ':' .. topic
81      endif
82    endif
83
84    if stridx(post, '(') == 0
85      return topic .. '()'
86    elseif pre =~# '^\s*:\=$' || pre =~# '\%(\\\||\)\@<!|\s*:\=$'
87      return ':' .. topic
88    elseif pre =~# '\<v:$'
89      return 'v:' .. topic
90    elseif pre =~# '<$'
91      return '<' .. topic .. '>'
92    elseif pre =~# '\\$'
93      return '/\' .. topic
94    elseif topic ==# 'v' && post =~# ':\w\+'
95      return 'v' .. matchstr(post, ':\w\+')
96    elseif pre =~# '&\%([lg]:\)\=$'
97      return "'" .. topic .. "'"
98    else
99      return topic
100    endif
101  endfunction
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]\>'
108  setlocal commentstring=#\ %s
109  " Set 'comments' to format dashed lists in comments, for Vim9 script.
110  setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:#
111else
112  setlocal commentstring=\"%s
113  " Set 'comments' to format dashed lists in comments, for legacy Vim script.
114  setlocal com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\"
115endif
116
117
118" Format comments to be up to 78 characters long
119if &tw == 0
120  setlocal 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")
128  let b:did_add_maps = 1
129
130  " Move around functions.
131  nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR>
132  xnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR>
133  nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR>
134  xnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR>
135  nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR>
136  xnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR>
137  nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR>
138  xnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR>
139
140  " Move around comments
141  nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
142  xnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
143  nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
144  xnoremap <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")
149  let 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".
155  let 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).
173  let 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