zig.vim 1.5 KB

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