>_
Zig and ZLS in NvChad (Neovim 0.11+)
Setting Up Zig and ZLS in NvChad (Neovim 0.11+)
A quick guide on installing the Zig compiler, building the Zig Language Server (ZLS) from source, and integrating them seamlessly into a modern NvChad setup using native Neovim LSP configurations.
1. Environment Setup
Install Zig
Install zig using package manager (Fedora/RHEL):
sudo dnf install zig
Install ZLS (Zig Language Server)
You can install ZLS directly from neovim using :Mason , or build it from source:
# Clone the source
git clone https://github.com/zigtools/zls
# go into the repo
cd zls
# Build from source
zig build -Doptimize=ReleaseFast
# Link the binary to our local system path
sudo ln -s $(pwd)/zig-out/bin/zls /usr/local/bin/zls
2. Neovim Configuration
Step A: Register the Plugins (lua/plugins/init.lua)
Add zig.vim for syntax handling and configure nvim-treesitter to ensure the Zig parser is automatically installed.
return {
{
"stevearc/conform.nvim",
-- event = 'BufWritePre', -- Uncomment to enable format-on-save globally
opts = require "configs.conform",
},
{
"neovim/nvim-lspconfig",
config = function()
require "configs.lspconfig"
end,
},
-- Zig syntax & auto-formatting
{
"ziglang/zig.vim",
ft = { "zig", "zon" },
init = function()
vim.g.zig_fmt_autosave = 1
end
},
-- Tree-sitter highlighting parser
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = { "zig" }
}
}
}
Step B: Configure the Native LSP Client (lua/configs/lspconfig.lua)
Using the neovim version 0.11++ vim.lsp.config architecture, loop through our lsp server and bind NvChad’s optimized UI capabilities and keymaps.
-- Load NvChad's diagnostic UI settings and defaults
require("nvchad.configs.lspconfig").defaults()
local servers = { "html", "cssls", "clangd", "zls" }
local nv_lsp = require("nvchad.configs.lspconfig")
-- Configure servers using native Neovim 0.11+ structures
for _, server in ipairs(servers) do
vim.lsp.config(server, {
autostart = true,
capabilities = nv_lsp.capabilities,
on_attach = nv_lsp.on_attach,
on_init = nv_lsp.on_init,
})
end
-- Initialize and activate the servers
vim.lsp.enable(servers)
3. Verification & Troubleshooting
- Lazy Loading check: when opening Neovim to an empty buffer, running
:Lazywill showzig.vimunder the Not loaded section. This is itentional. Then open any.zigfile and check:Lazyagain; it will showzig.vimunder the Loaded category. - LSP Status check: when inside an active
.zigfile, run:LspInfoto ensurezlshas correctly attached to the active buffer.