31383
|
1 " Vim filetype plugin file
|
|
2 " Language: Zig
|
|
3 " Upstream: https://github.com/ziglang/zig.vim
|
|
4
|
|
5 " Only do this when not done yet for this buffer
|
|
6 if exists("b:did_ftplugin")
|
|
7 finish
|
|
8 endif
|
|
9
|
|
10 let b:did_ftplugin = 1
|
|
11
|
|
12 let s:cpo_orig = &cpo
|
|
13 set cpo&vim
|
|
14
|
|
15 compiler zig_build
|
|
16
|
|
17 " Match Zig builtin fns
|
|
18 setlocal iskeyword+=@-@
|
|
19
|
|
20 " Recomended code style, no tabs and 4-space indentation
|
|
21 setlocal expandtab
|
|
22 setlocal tabstop=8
|
|
23 setlocal softtabstop=4
|
|
24 setlocal shiftwidth=4
|
|
25
|
|
26 setlocal formatoptions-=t formatoptions+=croql
|
|
27
|
|
28 setlocal suffixesadd=.zig,.zir
|
|
29
|
|
30 if has('comments')
|
|
31 setlocal comments=:///,://!,://,:\\\\
|
|
32 setlocal commentstring=//\ %s
|
|
33 endif
|
|
34
|
|
35 if has('find_in_path')
|
|
36 let &l:includeexpr='substitute(v:fname, "^([^.])$", "\1.zig", "")'
|
|
37 let &l:include='\v(\@import>|\@cInclude>|^\s*\#\s*include)'
|
|
38 endif
|
|
39
|
|
40 let &l:define='\v(<fn>|<const>|<var>|^\s*\#\s*define)'
|
|
41
|
|
42 if !exists('g:zig_std_dir') && exists('*json_decode') && executable('zig')
|
|
43 silent let s:env = system('zig env')
|
|
44 if v:shell_error == 0
|
|
45 let g:zig_std_dir = json_decode(s:env)['std_dir']
|
|
46 endif
|
|
47 unlet! s:env
|
|
48 endif
|
|
49
|
|
50 if exists('g:zig_std_dir')
|
|
51 let &l:path = &l:path . ',' . g:zig_std_dir
|
|
52 endif
|
|
53
|
|
54 let b:undo_ftplugin =
|
|
55 \ 'setl isk< et< ts< sts< sw< fo< sua< mp< com< cms< inex< inc< pa<'
|
|
56
|
|
57 augroup vim-zig
|
|
58 autocmd! * <buffer>
|
|
59 autocmd BufWritePre <buffer> if get(g:, 'zig_fmt_autosave', 1) | call zig#fmt#Format() | endif
|
|
60 augroup END
|
|
61
|
|
62 let b:undo_ftplugin .= '|au! vim-zig * <buffer>'
|
|
63
|
|
64 let &cpo = s:cpo_orig
|
|
65 unlet s:cpo_orig
|
|
66 " vim: tabstop=8 shiftwidth=4 softtabstop=4 expandtab
|