blob: e740a52849e3f22bfaae557a9090fde10fc7f576 [file] [log] [blame]
Bram Moolenaar86b48162022-12-06 18:20:10 +00001" 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
6if exists("b:did_ftplugin")
7 finish
8endif
9
10let b:did_ftplugin = 1
11
12let s:cpo_orig = &cpo
13set cpo&vim
14
15compiler zig_build
16
17" Match Zig builtin fns
18setlocal iskeyword+=@-@
19
20" Recomended code style, no tabs and 4-space indentation
21setlocal expandtab
22setlocal tabstop=8
23setlocal softtabstop=4
24setlocal shiftwidth=4
25
26setlocal formatoptions-=t formatoptions+=croql
27
28setlocal suffixesadd=.zig,.zir
29
30if has('comments')
31 setlocal comments=:///,://!,://,:\\\\
32 setlocal commentstring=//\ %s
33endif
34
35if has('find_in_path')
36 let &l:includeexpr='substitute(v:fname, "^([^.])$", "\1.zig", "")'
37 let &l:include='\v(\@import>|\@cInclude>|^\s*\#\s*include)'
38endif
39
40let &l:define='\v(<fn>|<const>|<var>|^\s*\#\s*define)'
41
42if !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
48endif
49
50if exists('g:zig_std_dir')
51 let &l:path = &l:path . ',' . g:zig_std_dir
52endif
53
54let b:undo_ftplugin =
55 \ 'setl isk< et< ts< sts< sw< fo< sua< mp< com< cms< inex< inc< pa<'
56
57augroup vim-zig
58 autocmd! * <buffer>
59 autocmd BufWritePre <buffer> if get(g:, 'zig_fmt_autosave', 1) | call zig#fmt#Format() | endif
60augroup END
61
62let b:undo_ftplugin .= '|au! vim-zig * <buffer>'
63
64let &cpo = s:cpo_orig
65unlet s:cpo_orig
66" vim: tabstop=8 shiftwidth=4 softtabstop=4 expandtab