NeoVim & NVChad & How to setup NVChad/NeoVim to be Zig's best friends ? :)

Hi,

On my Gentoo Linux I am using NeoVim in combination with the NVChad setup. I activated Treesitter for Zig (:TSInstall zig)…but had no luck in setting up for example lsp-config for it.
Any help is very appreciated to make NeoVim/NVChad a totally ziggified :wink: editor…

Cheers!
Tuxic

I’m not familiar with NVChad, but in my init.vim I’m using vim-plug as plugin manager, lsp and nvim-cmp for completion. Relevant bits:

The following Plug lines go between the call plug#begin() and call plug#end() lines.

Zig syntax, formatting, etc.

Plug 'ziglang/zig.vim'

for LSP / nvim-cmp completion:

Plug 'neovim/nvim-lspconfig'                                                                                                                                                                           
Plug 'hrsh7th/nvim-cmp'                                                                                                 
Plug 'hrsh7th/cmp-nvim-lsp'                                                                                             
Plug 'hrsh7th/cmp-buffer'                                                                                               
Plug 'hrsh7th/cmp-path'                                                                                                 
Plug 'hrsh7th/cmp-nvim-lua'                                                                                             
Plug 'hrsh7th/cmp-vsnip'                                                                                                
Plug 'hrsh7th/vim-vsnip'

Do a :PlugInstall and restart nvim for plugins ti kick-in.

Then for LSP to work with ZLS (installed separately):

lua <<EOF
  -- Setup nvim-cmp.
  local cmp = require'cmp'

  cmp.setup({
    snippet = {
      expand = function(args)
        vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
      end,
    },
    mapping = {
      ['<Tab>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
      ['<S-Tab>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
      ['<C-d>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.close(),
      ['<CR>'] = cmp.mapping.confirm({ select = true }),
    },
    sources = cmp.config.sources({
      { name = 'nvim_lsp' },
      { name = 'vsnip' }, -- For vsnip users.
    }, {
        { name = 'path' },
        { name = 'buffer', keyword_length = 3 },
    })
  })

  -- Setup lspconfig.
  local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
  require('lspconfig').zls.setup {
    capabilities = capabilities
  }
EOF

I cloned the ZLS repo and compiled it locally. Then I put a symlink to the zls binary in /usr/local/bin so it’s in the executable PATH. Hope this helps.

PS- I’m on macos by the way. It should also work on Linux.

Hi dude_the_builder,

Thank you VERY much for all the configuration help!!! :slight_smile:
Unfortunately it looks quite different to how “NvChad does it”…and I am quite new
to all the NeoVim-with-lua stuff. NvChad uses some different plugins for the same
task so I need to figure out how to prevent a clash.

Cheers!
Tuxic

1 Like

Hi,

some intermediate results from my side (NO “final solution” … only one step).

The installation of NvChad isn’t customized by me via …/lua/custom/.lua.

I only did a
:TSInstall zig

which installs the Zig-relevant stuff of TreeSitter and I did a
:MasonInstall zls

to install the ZLS languageserver for Zig.

When I will find out more, I will post it here.

Cheers!
Tuxic

1 Like