Overview

LunarVim strives to have support for all major languages. The is made possible by utilizing some of the great plugins in Neovim's ecosystem. Such plugins are nvim-lspconfigopen in new window, for LSP support, and Null-lsopen in new window to provide support for handling external formatters, such as prettieropen in new window and eslintopen in new window. Furthermore, LunarVim integrates with nvim-treesitteropen in new window to provider rich syntax highlighting and other language parsing magic.

If your language is not supported please check the following links and file a ticket so we can

At a glance

You can use the following commands to check some information about any language servers that you have configured.

  • :LvimInfo

    • Contains information about all the servers attached to the buffer you are editing and their current capabilities, such as formatting and go-to definition support. It also includes information related to any linters and formatters that are, or can be, configured.
    • keybind: <leader>Li
  • :LspInfo

    • Contains basic information about all the servers that are running.
    • keybind: <leader>li
  • :LspInstallInfo

LSP support

Installing and updating a server

Automatic server installation

By default, most supported language servers will get automatically installed once you open the supported file-type, e.g, opening a Python file for the first time will install Pyright and configure it automatically for you.

  • configuration option
lvim.lsp.automatic_servers_installation = true
1

Please refer to nvim-lsp-installeropen in new window to see the updated full list of currently available servers.

To install a supported language server:

:LspInstall `<your_language_server>`
1

You can also toggle <:LspInstallInfo> and interactively choose which servers to install.

Manually-configured servers

lvim.lsp.override contains a list of servers that should not be automatically configured by default, for example only tsserver is allowed for JS-family languages, and when a language has more than one server available, then the most popular one is usually chosen.

See the current list

:lua print(vim.inspect(lvim.lsp.override))
1

See the default list

:lua print(vim.inspect(require("lvim.lsp.config").override))
1

Note: any changes to lvim.lsp.override must be followed by :LvimCacheReset to take effect.

Server setup

LunarVim uses filetype plugins to enable lazy-loading the setup of a language server. A template generator is used to create ftplugin files and populate them with the setup call.

  • configuration option
lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "after", "ftplugin")
1

A typical setup call with default arguments

-- edit this file by running `:lua vim.cmd("edit " .. lvim.lsp.templates_dir .. "/lua.lua"))`
require("lvim.lsp.manager").setup("sumneko_lua")
1
2

Tip: You can quickly find these files by running <leader>Lf -> "Find LunarVim Files"

Overriding the default setup options

Add the server you wish to configure manually to lvim.lsp.override

vim.list_extend(lvim.lsp.override, { "pyright" })
1

Now you can set it up manually using the builtin lsp-manageropen in new window

--- list of options that should take predence over any of LunarVim's defaults
--- check the lspconfig documentation for a list of all possible options
local opts = {}
require("lvim.lsp.manager").setup("pyright", opts)
1
2
3
4

Alternatively, set it up using the lspconfig API directly

--- check the lspconfig documentation for a list of all possible options
local opts = {}
require("lspconfig")["pyright"].setup(opts)
1
2
3

Server settings

To set a setting for your language server:

:NlspConfig <TAB>
:NlspConfig <NAME_OF_LANGUAGE_SERVER>
1
2

This will create a file in $LUNARVIM_CONFIG_DIR/lsp-settings, to enable persistent changes. Refer to the documentation of nlsp-settingsopen in new window for a full updated list of supported language servers.

Note: Make sure to install jsonls for autocompletion.

Formatting

Set a formatter, this will override the language server formatting capabilities (if it exists)

local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
  { exe = "black" },
  {
    exe = "prettier",
    args = { "--print-width", "100" },
    filetypes = { "typescript", "typescriptreact" },
  },
}
1
2
3
4
5
6
7
8
9

Note: Formatters' installation is not managed by LunarVim. Refer to the each tool's respective manual for installation steps.

Custom arguments

It's also possible to add custom arguments for each formatter.

local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
  {
    exe = "prettier",
    ---@usage arguments to pass to the formatter
    -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
    args = { "--print-width", "100" },
  },
}
1
2
3
4
5
6
7
8
9

Note: remember that arguments cannot contains spaces, options such as --line-width 80 become either {'--line-width', '80'} or {'--line-width=80'}.

Multi languages per formatter

By default a formatter will attach to all the filetypes it supports.

local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
  {
    exe = "prettier",
    ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
    filetypes = { "typescript", "typescriptreact" },
  },
}
1
2
3
4
5
6
7
8

Note: removing the filetypes argument will allow the formatter to attach to all the default filetypes it supports.

Multi formatters per language

There are no restrictions on setting up multiple formatters per language

local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
  {
  { exe = "black", filetypes = { "python" } },
  { exe = "isort", filetypes = { "python" } },
  },
}
1
2
3
4
5
6
7

Lazy-loading the formatter setup

By default, all null-ls providers are checked on startup. If you want to avoid that or want to only set up the provider when you opening the associated file-type, then you can use filetype plugins for this purpose.

Let's take markdown as an example:

  1. create a file called markdown.lua in the $LUNARVIM_CONFIG_DIR/after/ftplugin folder
  2. add the following snippet
local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup({{exe = "prettier", filetypes = {"markdown"} }})
1
2

Formatting on save

You can disable auto-command and is to true by default.

  • configuration option
lvim.format_on_save = true
1

Linting

Set additional linters

local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
  { exe = "flake8" },
  {
    exe = "shellcheck",
    args = { "--severity", "warning" },
  },
  {
    exe = "codespell",
    filetypes = { "javascript", "python" },
  },
}
1
2
3
4
5
6
7
8
9
10
11
12

Note: linters' installation is not managed by LunarVim. Refer to the each tool's respective manual for installation steps.

Custom arguments

It's also possible to add custom arguments for each linter.

local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
  {
    exe = "shellcheck",
    ---@usage arguments to pass to the formatter
    -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
    args = { "--severity", "warning" },
  },
}
1
2
3
4
5
6
7
8
9

Note: remember that arguments cannot contains spaces, options such as --line-width 80 become either {'--line-width', '80'} or {'--line-width=80'}.

Multi linters per language

local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
  { exe = "flake8", filetypes = { "python" } },
  { exe = "codespell", filetypes = { "python" } },
}
1
2
3
4
5

Multi languages per linter

local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
  {
    exe = "codespell",
    ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
    filetypes = { "javascript", "python" },
  },
}
1
2
3
4
5
6
7
8

Note: removing the filetypes argument will allow the linter to attach to all the default filetypes it supports.

Lazy-loading the linter setup

By default, all null-ls providers are checked on startup. If you want to avoid that or want to only set up the provider when you opening the associated file-type, then you can use filetype plugins for this purpose.

Let's take python as an example:

  1. create a file called python.lua in the $LUNARVIM_CONFIG_DIR/after/ftplugin folder
  2. add the following snippet
local linters = require "lvim.lsp.null-ls.linters"
linters.setup({{exe = "flake8", filetypes = { "python" } }})
1
2
Last Updated: 11/19/2021, 7:55:55 AM
Contributors: kylo252, rebuilt, christianchiarulli, Pasi Bergman, Binx-Codes, Chris, Florian Hennig, Tran Phuc, William Boman