blob: cfd7102b8da3a3e7341a3d660b027c04968625f0 [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
Viktor Szépe3fc7a7e2023-08-23 21:20:00 +020020" Recommended code style, no tabs and 4-space indentation
Bram Moolenaar86b48162022-12-06 18:20:10 +000021setlocal 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
Christian Brabandtee17b6f2023-09-09 11:23:50 +020042" Safety check: don't execute zig from current directory
Christian Brabandt816fbcc2023-08-31 23:52:30 +020043if !exists('g:zig_std_dir') && exists('*json_decode') &&
Christian Brabandtf7ac0ef2023-09-06 20:41:25 +020044 \ executable('zig') && get(g:, 'zig_exec', get(g:, 'plugin_exec', 0))
45 \ && (fnamemodify(exepath("zig"), ":p:h") != s:tmp_cwd
46 \ || (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) != -1 && s:tmp_cwd != '.'))
Bram Moolenaar86b48162022-12-06 18:20:10 +000047 silent let s:env = system('zig env')
48 if v:shell_error == 0
49 let g:zig_std_dir = json_decode(s:env)['std_dir']
50 endif
51 unlet! s:env
52endif
Christian Brabandtf7ac0ef2023-09-06 20:41:25 +020053unlet! s:tmp_cwd
Bram Moolenaar86b48162022-12-06 18:20:10 +000054
55if exists('g:zig_std_dir')
56 let &l:path = &l:path . ',' . g:zig_std_dir
57endif
58
59let b:undo_ftplugin =
60 \ 'setl isk< et< ts< sts< sw< fo< sua< mp< com< cms< inex< inc< pa<'
61
62augroup vim-zig
63 autocmd! * <buffer>
64 autocmd BufWritePre <buffer> if get(g:, 'zig_fmt_autosave', 1) | call zig#fmt#Format() | endif
65augroup END
66
67let b:undo_ftplugin .= '|au! vim-zig * <buffer>'
68
69let &cpo = s:cpo_orig
70unlet s:cpo_orig
71" vim: tabstop=8 shiftwidth=4 softtabstop=4 expandtab