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

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 FileType events; when a buffer's filetype matches the server's filetypes, the server starts
  • Neovim also locates the root directory using the server's root_markers before 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.lua file (with :set exrc) to activate servers per-project
  • Call vim.lsp.disable('server-name') to stop a server without restarting Neovim
  • Use :LspInfo to verify which servers are running and their root directories
  • Before Neovim 0.11, the equivalent is require('lspconfig').server.setup({})

Next

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?