Barbarian Meets Coding
barbarianmeetscoding

WebDev, UX & a Pinch of Fantasy

5 minutes readneovim

Neovim - Using modern vim

Neovim is a fork of vim which aims at doing a major refactoring of the codebase with a focus on modern development workflows and making vim more extensible. (Check the Neovim documentation which describes Neovim’s vision.)

Table of Contents

Migrating to Neovim

Installing Neovim

Note that all config instructions assume that you’re running neovim on MacOS, if you aren’t take a look at neovim docs to find the correct paths and such.

The most straightforward way to install Neovim in MacOS is to use homebrew, the uber popular MacOS package manager:

# Install stable release
$ brew intall neovim
# Install latest development version
$ brew install --HEAD neovim
# Update development version
$ brew upgrade neovim --fetch-HEAD

Setting up a vimrc

The first thing you need to know is that neovim is designed to run side by side with vim. That means that it has its own executable nvim and its own configuration file, by default, in ~/.config/nvim/init.vim. An easy way to get started with neovim is to just have it load your current vimrc file. In order to to that you create a init.vim file in the folder above and then write the following:

" load current vimrc file
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vim/vimrc

You can find more info about vimrc with neovim using vim’s help :help vimrc.

Using Neovim

Since for the most part Neovim follows the exact same principles as Vim. Refer to the Vim article in this wiki to learn more about how to use Vim and Neovim.

From init.vim to init.lua

Neovim 0.5 has embedded a lua runtime that allows you to write your vim configuration using Lua. From version 0.5 you can migrate your existing init.vim to init.lua the advantages of this approach is that you have a full blown programming language that you can take advantage of to configure and enhance Neovim.

You can also still use your init.vim in combination with a Lua configuration by loading a Lua module with your additional Lua configuration from your vimrc:

# Your config lua file is in the lua runtimepath:
# $NVIM_FOLDER/lua/config.lua 
# Now you can require it from your vimrc init.vim
lua require('config')

This is a great approach as you gradually migrate your existing vimrc to lua, or if you want to continue using some Vim plugins. (Note that you can also execute vimscript from lua so another possibility is to keep a minimal config in vimscript being called from your main lua configuration).

Refer to :h lua to find more information about the lua runtime in Neovim.

Plugins

Neovim comes with full support for Lua as a language for authoring neovim plugins. Here’s a list of useful neovim plugins and a small guide on how to write your own plugins

Neovim still has full compatibility with Vim plugins. Take a look at the Vim plugins section in this wiki for more plugins not written in Lua.

Limitations

  • Neovim has no GUI, it is a text based text editor. Because of this it has some limitations like not being able to set the font size. It just uses the size of the font used in the terminal which hosts neovim. That being said, the idea with Neovim is to work as an engine for other projects who will focus on building GUIs on top of Neovim. These are some examples:

Things that are hard with Neovim today

  • The experience to setup Vim for a given programming language is not standardized and can be quite complicated. One needs to do a bunch of research themselves to find a set of useful plugins. It’d be great if there was an standardize way to set up neovim for a new programming language and/or recommended extensions.
  • It’d be great if neovim had a marketplace for plugins like VSCode.

References and resources


Jaime González García

Written by Jaime González García , dad, husband, software engineer, ux designer, amateur pixel artist, tinkerer and master of the arcane arts. You can also find him on Twitter jabbering about random stuff.Jaime González García