LSP Setup in LazyVim
Language Server Protocol (LSP) setup is one of the most notoriously difficult parts of configuring vanilla Neovim. LazyVim solves this by automatically managing LSP servers, formatters, and linters using Mason and nvim-lspconfig.
How LazyVim handles LSP
Out of the box, LazyVim provides a robust LSP foundation:
- Mason (
williamboman/mason.nvim) installs servers. - Mason-Lspconfig bridges Mason with Neovim's built-in LSP client.
- Keymaps, capabilities, and autocommands (like format-on-save) are wired up automatically.
Method 1: Using LazyVim Extras (Recommended)
The easiest way to get full language support is via LazyVim Extras. Extras are curated configurations for specific languages that include the best LSP, formatter, linter, and Treesitter parsers.
- Open Neovim and run
:LazyExtras. - Navigate to the
langsection. - Press
xto enable a language (e.g.,lang.typescript,lang.python). - Restart Neovim. LazyVim will automatically download and configure everything needed for that language!
Method 2: Adding servers manually
If an Extra doesn't exist for your language, or you want fine-grained control, you can add servers by extending the nvim-lspconfig options in lua/plugins/lsp.lua:
return {
"neovim/nvim-lspconfig",
opts = {
servers = {
-- Enable a server with default settings
pyright = {},
-- Enable a server with custom settings
tsserver = {
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = "all",
},
},
},
},
},
},
}
Formatting with conform.nvim
LazyVim uses conform.nvim for formatting. To add a formatter:
return {
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
lua = { "stylua" },
javascript = { "prettier" },
},
},
}
Linting with nvim-lint
For linters, LazyVim uses nvim-lint:
return {
"mfussenegger/nvim-lint",
opts = {
linters_by_ft = {
javascript = { "eslint_d" },
},
},
}
Comparison: Vanilla vs LazyVim
| Feature | Vanilla Neovim | LazyVim |
|---|---|---|
| Installation | Manual via Mason or system package manager | Automatic via Mason / LazyExtras |
| Server Config | Write setup boilerplate for each server | Just add server name to opts.servers |
| Format on save | Write custom autocommands | Works out of the box with conform.nvim |
| Keymaps | Map manually in LspAttach autocommand | Pre-configured (K, gd, gr, etc.) |