How do I configure an LSP client in Neovim 0.11 without using nvim-lspconfig?
Answer
vim.lsp.config()
Explanation
Neovim 0.11 introduced vim.lsp.config() and vim.lsp.enable() as a built-in API for declaring LSP client configurations without relying on the nvim-lspconfig plugin. This lets you register named LSP clients and activate them for specific filetypes using pure Lua.
How it works
vim.lsp.config('name', { ... })registers a named LSP configuration with fields likecmd,filetypes,root_markers, andsettingsvim.lsp.enable('name')activates the registered config for matching filetypes- Neovim also auto-discovers config files placed in
~/.config/nvim/lsp/<name>.lua
Example
-- In init.lua or a plugin file:
vim.lsp.config('lua_ls', {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = { '.luarc.json', '.git' },
settings = {
Lua = { diagnostics = { globals = { 'vim' } } },
},
})
vim.lsp.enable('lua_ls')
Alternatively, create ~/.config/nvim/lsp/lua_ls.lua with just the config table, and Neovim picks it up automatically.
Tips
- Pass
falseas the second argument tovim.lsp.enable()to disable a configured server:vim.lsp.enable('lua_ls', false) - Multiple servers can share the same filetype — Neovim manages lifecycle independently
- This is a lightweight alternative to
nvim-lspconfigfor users who want fewer plugin dependencies - Still compatible with
nvim-lspconfigif you prefer a gradual migration