Conquer of Completion (CoC)
- Install CoC
- Install zig.vim
- Install jsonc.vim (optional, so that comments in json are not highlighted as errors)
- place the following snippet in your coc-settings.json(open it using:CocConfig)
- place the following snippet in your init.lua/init.vim/.vimrc
// coc-settings.json
{
  // All nested settings will only affect Zig files.
  "[zig]": {
    // enable format-on-save from CoC + ZLS
    //
    // Formatting with ZLS matches `zig fmt`.
    // The Zig FAQ answers some questions about `zig fmt`:
    // https://github.com/ziglang/zig/wiki/FAQ
    "coc.preferences.formatOnSave": true,
    // Show inlay hints in the editor. Inlay hints are short annotations within the code,
    // which show variable types or parameter names.
    // "inlayHint.enable": true,
    // Use the language server to perform code highlighting
    "semanticTokens.enable": true
  },
  "languageserver": {
    "zls": {
      // use `"command": "zls"` if `zls` is in your PATH
      "command": "/path/to/zls_executable",
      "filetypes": [ "zig", "zon" ],
      // There are two ways to set config options:
      //   - edit your `zls.json` that applies to any editor that uses ZLS
      //   - set in-editor config options with the `settings` field below.
      //
      // Further information on how to configure ZLS:
      // https://zigtools.org/zls/configure/
      "settings": {
        // Whether to enable build-on-save diagnostics
        //
        // Further information about build-on save:
        // https://zigtools.org/zls/guides/build-on-save/
        // "zls.enable_build_on_save": true,
        // omit the following line if `zig` is in your PATH
        "zls.zig_exe_path": "/path/to/zig_executable"
      }
    }
  }
}
-- init.lua (Neovim only)
-- don't show parse errors in a separate window
vim.g.zig_fmt_parse_errors = 0
-- disable format-on-save from `ziglang/zig.vim`
vim.g.zig_fmt_autosave = 0
" init.vim or .vimrc
" don't show parse errors in a separate window
let g:zig_fmt_parse_errors = 0
" disable format-on-save from `ziglang/zig.vim`
let g:zig_fmt_autosave = 0
Code Actions on save
source.fixAll
-- init.lua (Neovim only)
vim.api.nvim_create_autocmd('BufWritePre',{
  pattern = {"*.zig", "*.zon"},
  command = "call CocActionAsync('fixAll')"
})
autocmd BufWritePre *.zig,*.zon call CocActionAsync('fixAll')
source.organizeImports
-- init.lua (Neovim only)
vim.api.nvim_create_autocmd('BufWritePre',{
  pattern = {"*.zig", "*.zon"},
  command = "call CocActionAsync('organizeImport')"
})
autocmd BufWritePre *.zig,*.zon call CocActionAsync('organizeImport')
Per-project config
Coc allows setting LSP settings per project via a .vim/coc-settings.json file. Use the :CocLocalConfig to create and open the settings file in your workspace folder. Run :h coc-configuration for more information.
If the use case for per-project config is to set the path to the Zig or ZLS executable, consider using direnv to add it to your $PATH or use a version manager for Zig and ZLS.