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

How do I enable a built-in LSP server in Neovim 0.11 without installing plugins?

Answer

vim.lsp.enable()

Explanation

Neovim 0.11 ships with a native mechanism to configure and activate LSP servers directly from your init.lua, without nvim-lspconfig. The vim.lsp.enable() function tells Neovim to auto-start a server whenever its target filetype is opened.

How it works

Server definitions live in ~/.config/nvim/lsp/<name>.lua. Each file returns a table with the server's startup parameters. vim.lsp.enable() registers those definitions so Neovim knows to launch the server automatically on matching files.

  • cmd — the executable and its arguments
  • filetypes — which file types should trigger the server
  • root_markers — files/dirs that indicate the project root

Example

-- ~/.config/nvim/lsp/lua_ls.lua
return {
  cmd = { 'lua-language-server' },
  filetypes = { 'lua' },
  root_markers = { '.luarc.json', 'init.lua', '.git' },
}
-- ~/.config/nvim/init.lua
-- Enable one server:
vim.lsp.enable('lua_ls')

-- Or enable several at once:
vim.lsp.enable({ 'lua_ls', 'pyright', 'ts_ls' })

Open any .lua file and :LspInfo will confirm the server is attached.

Tips

  • Use vim.lsp.config('*', { capabilities = vim.lsp.protocol.make_client_capabilities() }) to set default capabilities for every server
  • Combine with vim.api.nvim_create_autocmd('LspAttach', ...) to add buffer-local keymaps only when a server is present
  • :checkhealth vim.lsp diagnoses missing executables or configuration errors

Next

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