Neovim: The modern text editor that enhances your productivity in Linux

Introduction

Neovim has been born as an evolution of the Vim classic, designed to offer a more modern and flexible editing experience in Linux environments. Its architecture is designed to be extensible, facilitating the integration of plugins written in Lua and improving performance against its predecessor.

History and philosophy

The Neovim project was launched in 2014 with the aim of resolving some of Vim's technical debts and opening the door to new functionalities. Developers wanted to separate the logic from the editor from the user interface, allowing graphical, terminal and embedded interfaces to be communicated through a msgpack-based API.

Main advantages over Vim

  • Better support for graphic interfaces and drinks.
  • Msgpack-based plugin API, more robust and documented.
  • Native integration of Lua language for configuration and plugins.
  • More frequent updates and an active community that drives constant improvements.
  • Reduced resource consumption in intensive use scenarios.

Installation in popular Linux distributions

To install Neovim in Ubuntu or Debian:

sudo apt update
sudo apt install neovim

In Fedora:

sudo dnf install neovim

In Arch Linux:

sudo pacman -S neovim

If you prefer to compile from the source code to get the latest stable version, follow these steps:

git clone https://github.com/neovim/neovim.git
cd neovim
make CMAKE_BUILD_TYPE=Release
sudo make install

Initial configuration

The configuration file is found in~/.config/nvim/init.vimif you use Vimscript, or~/.config/nvim/init.luaIf you prefer Lua. A basic example in Vimscript:

set number
set relativenumber
syntax on
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab

The same adjustment in Lua is written as follows:

vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.syntax = 'on'
vim.opt.filetype = 'on'
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true

Plugin management

The most popular plugin managers in Neovim arepacker.nvimandlazy.nvim. Both allow you to install, update and remove plugins with few commands.

Example of packer.nvim installation:

git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim

Then on youinit.luaYou can define the plugins:

require('packer').startup(function(use)
use 'wbthomason/packer.nvim' -- packer se gestiona a sí mismo
use 'nvim-telescope/telescope.nvim'
use 'nvim-treesitter/nvim-treesitter'
use 'neovim/nvim-lspconfig'
use 'hrsh7th/nvim-cmp'
end)

For lazy.nvim the process is similar, but with a syntax that loads plugins only when needed.

LSP and self-completed

The Language Server Protocol (LSP) allows you to obtain functions like self-completed, go to definition and display documentation directly within the editor. Neovim includes an integrated LSP client that is configured bylspconfig.

Example of configuration for Python language server:

require'lspconfig'.pyright.setup{}

For self-completed it is usually combinednvim-cmpwith sources such asluasnipandbuffer:

local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
[''] = cmp.mapping.scroll_docs(-4),
[''] = cmp.mapping.scroll_docs(4),
[''] = cmp.mapping.complete(),
[''] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, {
{ name = 'buffer' }
})
})

Integration with development tools

Neovim is easily adapted to workflows including Git, construction systems and containers.

  • Git: plugins asgitsigns.nvimshow changes directly to the margin.
  • Make or Ninja: you can run:makeand see the errors in the location list.
  • Docker: by:terminalYou can open a shell inside a container and work with the mounted files.
  • Tests: integrate frameworks aspytestorjestby async tasks withvim.fn.jobstart.

Customization of theme and interface

The appearance of Neovim is controlled by color schemes and state bars.

Popular color schemas:

  • gruvbox- warm tones and balanced contrast.
  • onedark- inspiration on the topic of VS Code.
  • catpuccin- soft and modern pallets.

To apply a scheme, simply add:

colorscheme gruvbox

The status bar can be improved with plugins aslualine.nvimorgestiyline.nvim, showing information about the mode, Git branch, LSP diagnosis and more.

Productivity: macros, records and shortcuts

Neovim inherits Vim's powerful modal editing model, which allows to record macros for repetitive sequences.

Example of simple macro:

qq0y$jPq

This macro copies the current line and hits it below. To run it several times use@qor a number followed by@q.

The records (a-z, 0-9, '"') store deleted or copied text and can be used at any time.

In addition, you can create custom mapping to quickly access frequent functions:

vim.keymap.set('n', 't', ':terminal')
vim.keymap.set('n', 'ff', require('telescope.builtin').find_files)

Common problem solution

  • The plugins are not loaded: check that the route ofruntimepathinclude the directory where you installed them.
  • The colors look wrong in old terminals: make sure your terminal supports 24-bit colors or uses a scheme that works in 256 colors.
  • The LSP does not start: check that the language server is installed and accessible on your$PATH.

Community and learning resources

Neovim has an active community on platforms such as GitHub, Reddit and Discord. Some recommended resources:

  • The official wiki:
  • The YouTube ChannelNeovim from scratchfor tutorials step by step.
  • The bookLearn Vimscript the Hard Wayadapted to Lua.
  • Forums likeVi and Vim Stack Exchangewhere you can ask specific questions.

Conclusion

Neovim represents a powerful and modern option for Linux developers and users looking for a highly configurable, fast and extensible text editor. Its Lua-based architecture, its growing plugin ecosystem and its focus on extensibility make it an essential tool for any workflow.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish