How do I activate a configured language server in Neovim 0.11 for specific filetypes?
Answer
vim.lsp.enable('server-name')
Explanation
vim.lsp.enable() is the Neovim 0.11 counterpart to vim.lsp.config(). Once a server is configured, calling vim.lsp.enable() tells Neovim to automatically start that server whenever a matching buffer is opened — no additional autocmds or plugin manager required. You can enable multiple servers in a single call by passing a list.
How it works
- Accepts a single server name string or a list of names
- Neovim hooks into
FileTypeevents; when a buffer's filetype matches the server'sfiletypes, the server starts - Neovim also locates the root directory using the server's
root_markersbefore launching - Multiple servers can be active in the same buffer if their filetypes overlap
Example
-- Enable a single server
vim.lsp.enable('clangd')
-- Enable multiple servers at once
vim.lsp.enable({ 'clangd', 'pyright', 'lua_ls' })
Typically placed in init.lua or a project-specific config file. The servers must have been configured first with vim.lsp.config().
Tips
- Use
vim.lsp.enable()in a project.nvim.luafile (with:set exrc) to activate servers per-project - Call
vim.lsp.disable('server-name')to stop a server without restarting Neovim - Use
:LspInfoto verify which servers are running and their root directories - Before Neovim 0.11, the equivalent is
require('lspconfig').server.setup({})