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

Automatic server installation

By default, most supported language servers [^1] 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.

[^1]: Please note that only TSServer is configured by default for JS-family languages, and when a language has more than one server available, then the most popular is usually chosen.

Installing and updating a server

To install a supported language server:

:LspInstall `<your_language_server>`
1

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

LSP 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"

Server configuration

To set a configuration 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.

Overriding the default configuration

Add this to you config.lua

lvim.lsp.override = { "pyright" }
1

Now you can either set it up manually, or replace only a subset of LunarVim's default options

local opts = {} -- check the lspconfig documentation for a list of all possible options
require("lvim.lsp.manager").setup("pyright", opts)
1
2

Blacklisting a server

If you want to exclude a certain server while maintaining the auto-installation functionality then you can choose to override it. This will prevent it from being re-installed again and will also mean that you have to configure it manually.

Formatting

To enable formatting for javascript for example, add the following to your config.lua

lvim.lang.javascript.formatters = { { exe = "prettier" } }
1

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.

lvim.lang.javascript.formatters = { { exe = "prettier", args = { "--print-with", "100" } } }

1
2

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

Multi formatters per language

lvim.lang.python.formatters = { { exe = "black" }, { exe = "isort" } }
1

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/ftplugin folder
  2. add the following snippet
local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup({{exe = "prettier", filetypes = {"markdown"} }})
1
2

Multi languages per formatter

local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup({{exe = "prettier", filetypes = {"javascript", "json"} }})
1
2

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

This method will not disable the formatting capability of the respective language server. Thus, you might start getting prompted to select it as a formatter. You need to disable this capability manually to avoid that.

-- here's an example to disable formatting in "tsserver" and "jsonls"
lvim.lsp.on_attach_callback = function(client, _)
  if client.name == "tsserver" or client.name == "jsonls" then
    client.resolved_capabilities.document_formatting = false
    client.resolved_capabilities.document_range_formatting = false
  end
end
1
2
3
4
5
6
7

Formatting on save

This is controlled by an auto-command and is to true by default.

  • configuration option
lvim.format_on_save = true
1

Linting

To enable a linter for bash for example, add the following to your config.lua

lvim.lang.sh.linters = { { exe = "shellcheck" } }
1

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.

lvim.lang.sh.linters = { { exe = "shellcheck", args = { "--sverity", "error" } } }

1
2

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

Multi formatters per language

lvim.lang.python.linters = { { exe = "flake8" }, { exe = "pylint" } }
1

Multi languages per formatter

local linters = require "lvim.lsp.null-ls.linters"
linters.setup({{exe = "eslint", filetypes = {"javascript", "typescript", "vue"} }})
1
2

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 typescript as an example:

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