Neovim for Beginners — LSP (Part 1)

Configure the built-in LSP (Language Server Protocol) client.

alpha2phi

--

Neovim for Beginners — LSP

Neovim supports the Language Server Protocol (LSP), which means it acts as a client to LSP servers and includes a Lua framework vim.lsp (:h vim.lsp) for building enhanced LSP tools. The language servers are provided by third parties.

In this article, we are going to

  • Configure the nvim-lspconfigplugin that provides common configuration for various language servers.
  • Configure a language server installer to make it easy to install any language server.
  • Configure key mappings for the LSP features.
  • Configure the vim.lsp.omnifunc function (:h vim.lsp.omnifunc) as the omnifunc(:h omnifunc) handler. The omnifuncoption specifies a function to be used for insert mode omni completion with CTRL-X CTRL-O.
  • Configure the vim.lsp.formatexpr function as the handler for formatexpr(:h formatexpr). The formatexpr option specifies an expression that is evaluated to format a range of lines for the gqoperator or automatic formatting (:h formatoptions).
  • Configure LSP completion using coq.nvim and nvim-cmp. Previously, we talked about these two completion plugins in this article.

This article is part of the Neovim for Beginners series.

The Neovim configuration files can be found in this repository.

Unlike treesitter or ctags, LSP facilitates features like go-to-definition, find-references, hover, completion, rename, format, refactor, etc., using semantic whole-project analysis. We will get started by installing and configuring nvim-lspconfig.

nvim-lspconfig

nvim-lspconfig is a collection of common configurations for Neovim’s built-in language server client.

Installation

In thelua/plugins.lua file, add the following lines.

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.