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 theirfiletypesandroot_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-lspconfigis still required