vimtricks.wiki Concise Vim tricks, one at a time.

How do I configure a language server in Neovim 0.11 without any plugins using the built-in vim.lsp.config?

Answer

vim.lsp.config('*', { ... })

Explanation

Neovim 0.11 introduced vim.lsp.config() and vim.lsp.enable() as built-in alternatives to the popular nvim-lspconfig plugin. You can now configure and activate language servers entirely from your Lua config without installing anything extra.

How it works

  • vim.lsp.config(name, opts) stores configuration for a named server (or '*' for global defaults)
  • vim.lsp.enable(names) activates listed servers and attaches them based on their filetypes and root_markers

Example

" From the command line or init.lua
-- Set shared defaults for all servers
vim.lsp.config('*', {
  root_markers = { '.git', 'package.json' },
})

-- Configure a specific server
vim.lsp.config('lua_ls', {
  filetypes = { 'lua' },
  root_markers = { '.luarc.json', '.git' },
  settings = {
    Lua = { diagnostics = { globals = { 'vim' } } },
  },
})

-- Enable it (can also be done per-filetype via LspAttach autocmd)
vim.lsp.enable('lua_ls')

Tips

  • Server configs can also live in ~/.config/nvim/lsp/lua_ls.lua — Neovim auto-loads them by name
  • vim.lsp.enable() accepts a string or table of server names
  • Use :lua vim.lsp.get_clients() to verify servers are running
  • This API is available in Neovim 0.11+ only; for older versions, nvim-lspconfig is still required

Next

How do I enable matchit so % jumps between if/else/end style pairs?