Neovim

From ArchWiki

Neovim is a fork of Vim aiming to improve the codebase, allowing for easier implementation of APIs, improved user experience and plugin implementation.

Installation

Install the neovim package, or neovim-gitAUR for the latest development version, which strongly encourages the use of lua as its main configuration language. To make the system clipboard work with Neovim, you may need to install xclip (X11) or wl-clipboard (Wayland).

Note: With neovim, some of its features are delegated to external "providers". For Python providers, use python-pynvim. For clipboard providers, see provider-clipboard or the :help provider-clipboard neovim command.

It is also possible to install one of many GUIs and other related projects, most of them are in official repositories or in AUR:

Configuration

Nvim's user-specific configuration file is located at $XDG_CONFIG_HOME/nvim/init.vim, by default ~/.config/nvim/init.vim. The global configuration file is loaded from $XDG_CONFIG_DIRS/nvim/sysinit.vim (by default /etc/xdg/nvim/sysinit.vim) if it exists, or if it does not, from /usr/share/nvim/sysinit.vim which should not be user-edited. [1] By default, the former global configuration file does not exist. If you create the former file, you may wish to have it source the latter if you still want the functionality it provides, which is allowing pacman-installed vim packages to work with Nvim.

Nvim is compatible with most of Vim's options, however there are options specific to Nvim. For a complete list of Nvim options, see Neovim's help file.

Nvim's data directory is located in ~/.local/share/nvim/ and contains swap for open files, the ShaDa (Shared Data) file, and the site directory for plugins.

Starting from Nvim's version 0.5, it is possible to setup Nvim via Lua, by default ~/.config/nvim/init.lua, the API is still young, but common configurations work out-of-the-box without much more steps. See [2] for suggestions on how to convert your current configuration. At the moment there is is not much of an advantage when using init.lua vs the common init.vim, but when correctly done, Lua provides a small improvement in startup times, and it becomes specially useful when using several plugins written in lua, due to ease of configuration.

Migrating from Vim

If you wish to migrate your existing Vim configuration to Nvim, simply copy your ~/.vimrc to ~/.config/nvim/init.vim. If applicable, copy the contents of ~/.vim/autoload/ to ~/.local/share/nvim/site/autoload/.

Shared Configuration between Vim and Nvim

Neovim uses $XDG_CONFIG_HOME/nvim instead of ~/.vim as its main configuration directory and $XDG_CONFIG_HOME/nvim/init.vim instead of ~/.vimrc as its main configuration file.

If you wish to continue using Vim and wish to source your existing Vim configuration in Nvim, see nvim-from-vim or the :help nvim-from-vim neovim command.

Loading plugins

Vim/Nvim plugins installed from official repositories or AUR get automatically sourced by /etc/xdg/nvim/sysinit.vim, so there is no need to take any extra steps. A vast amount of plugins can be found on both places, but the most recommended way to add plugins is by using a plugin manager, most commonly used are vim-plug which works for both Vim and Nvim, and packer which only works on Nvim 0.5 or newer and is written in lua. Both of them allow for expressive configurations, ranging from github branch to runtime commands.

Most plugins written for vim work without much effort on Nvim, but not every plugin written for Nvim works for Vim, so if your intention is to ensure a compatible configuration, stick to a traditional init.vim or .vimrc

Tips and tricks

Replacing vi and vim with neovim

Setting $VISUAL and $EDITOR environment variables should be sufficient in most cases.

Some applications may hardcode vi or vim as default editor, to use neovim in their place, install neovim-symlinksAUR or neovim-drop-inAUR.

Symlinking init.vim to .vimrc

As neovim is mostly compatible with standard vim, you can symlink nvim/init.vim to your old .vimrc to keep old configuration options:

$ ln -s ~/.vimrc ~/.config/nvim/init.vim

If you want some lines to be specific to each version, you can use an if block in your .vimrc file:

if has('nvim')
    " Neovim specific commands
else
    " Standard vim specific commands
endif

Adding true color support to neovim

The READMEs of this project explain how to add 24-bits "True Color" support to your syntax highlighting and how to use a color picker to see how it looks in real-time. Comes with the syntax highlighting of the author (if installed) for C++.

Language Server Protocol

Neovim contains a built-in Language Server Protocol client and the nvim-lspconfig plugin provides common configurations for it.

Language servers can be installed natively using the following packages:

LSP config Language LSP server package
als Ada/SPARK ada_language_serverAUR
angularls Angular
bashls BASH bash-language-server
ccls C, C++, Objective-C ccls ccls-gitAUR
clangd C++ clang
clojure_lsp Clojure clojure-lsp-binAUR
cmake CMake cmake-language-serverAUR
codeqlls CodeQL codeqlAUR
cssls CSS, LESS, SASS vscode-css-languageserver
dartls Dart dart
denols JavaScript, TypeScript deno
dhall_lsp_server Dhall dhall-lsp-server
diagnosticls General purpose diagnostic-languageserverAUR
dockerls Dockerfile dockerfile-language-serverAUR
efm General purpose efm-langserverAUR
elixirls Elixir elixir-lsAUR
elmls Elm elm-language-serverAUR
erlangls Erlang erlang_ls-gitAUR
flow Flow flowAUR
fortls Fortran fortran-language-serverAUR
fsautocomplete F#
gdscript GDScript godot
ghcide Haskell ghcideAUR
gopls GOlang gopls
graphql GraphQL graphql-lspAUR
groovyls Groovy groovy-language-server-gitAUR
haxe_language_server Haxe
hie Haskell haskell-ide-engineAUR
hls Haskell haskell-language-server
html HTML vscode-html-languageserver
intelephense PHP nodejs-intelephenseAUR
java_language_server Java java-language-serverAUR
jdtls Java jdtlsAUR
jedi_language_server Python jedi-language-server
jsonls JSON vscode-json-languageserver
julials Julia
kotlin_language_server Kotlin kotlin-language-serverAUR
leanls Lean
metals Scala metalsAUR
nimls Nim
ocamlls OCaml, Reason
ocamllsp OCaml, Reason ocaml-lsp-gitAUR
omnisharp OmniSharp omnisharp-roslynAUR
perlls Perl perl-perl-languageserverAUR
phpactor PHP
powershell_es PowerShell
purescriptls PureScript purescript-language-serverAUR
pylsp Python python-lsp-server
pyright Python pyright
r_language_server R
racket_langserver Racket
rescriptls ReScript
rls Rust rls-gitAUR
rnix nix rnix-lsp-gitAUR
rome Rome
rust_analyzer Rust rust-analyzer
scry Crystal scry-gitAUR
solargraph Ruby ruby-solargraphAUR
sorbet Ruby
sourcekit C, C++, Objective-C swift-languageAUR
sqlls SQL sql-language-serverAUR
sqls SQL
stylelint_lsp stylelint
sumneko_lua Lua lua-language-server
svelte Svelte nodejs-svelte-language-serverAUR
svls SystemVerilog
terraformls Terraform terraform-lsAUR
texlab (La)TeX texlab
tflint Terraform tflintAUR
tsserver TypeScript
vala_ls Vala vala-language-serverAUR
vimls Vim vim-language-serverAUR
vls V
volar Vue 3 volar-server-binAUR
vuels Vue 2 nodejs-vlsAUR
yamlls YAML yaml-language-server
zeta_note Markdown
zls Zig zls-binAUR

Troubleshooting

Cursor is not restored to previous state after exit

If after exiting neovim cursor is still blinking see solution on neovim FAQ.

See also