How to setup NeoVim configuration file

NeoVim is a super flexible and configurable editor. However, setting up its configuration file can a bit confusing for the beginners

Neovim, born as a modern fork of the venerable Vim text editor, has emerged as a powerful tool that revolutionizes the text editing experience for developers and power users alike. With its commitment to compatibility, extensibility, and performance, Neovim has won the hearts of a growing community of enthusiasts. Neovim retains all the beloved features of Vim while introducing significant enhancements and new capabilities.



A text editor with a command-line interface, offers several advantages over a graphical Integrated Development Environment (IDE):

  • Firstly, Neovim embraces simplicity, stripping away unnecessary visual clutter and providing a clean and distraction-free environment. This minimalistic approach allows programmers to focus solely on their code, promoting a more immersive and efficient coding experience.

  • Secondly, Neovim boasts remarkable speed and responsiveness, enabling rapid navigation, editing, and searching within large codebases. It leverages the power of keyboard-centric workflows, allowing programmers to execute commands and perform complex operations with lightning-fast keystrokes.
  • Additionally, Neovim's extensive plugin ecosystem provides immense flexibility and customization options. Programmers can tailor their editing environment to suit their specific needs, enhancing productivity and workflow efficiency.

  • Finally, Neovim's lightweight nature makes it highly versatile, running smoothly on a variety of platforms and even on remote servers. Whether you're working on a beefy development machine or a modest device, Neovim remains a reliable companion in the world of code.
I'll asume at this point that you know the basic commands for entering and exiting Neovim. As well as the basic commands for inserting text and saving file changes. If not, you should first get some knowledge about that before we dig into the configuration of Neovim. Otherwise, it is going to be a painful experience for you. Ok, so let's get started.

Download Neovim

The first thing that we need to do is to download the latest stable release of Neovim from their github repository for the corresponding operating system that you are using.

Install Neovim

Next, we install Neovim:

Windows

We install the .msi file following the installation wizard.

Linux

We just unpack the .tar.gz file into the desired folder. For example /usr/local/bin:

>sudo tar zxvf nvim-linux64.tar.gz /usr/local/bin


Then we update the PATH variable of our shell configuration file. For example .zshrc:

>vi .zshrc
export PATH=$PATH:/usr/local/bin/nvim-linux64

Configure Neovim

Once we have Neovim installed on our system, we can start configuring it. Although Neovim provides compatibility with vim, and you can use vimscript for configuring almost all the vim options and features in Neovim. I'll stick just to using lua, because it is faster, more powerful and clearer to understand. So we'll start by creating an init.lua file in the folder where Neovim looks for its configuration. This file will be the equivalent of the .vimrc configuration file for vim that we should place at our home folder. For the case of Neovim, the location of the init.lua file depends on the operating system that you are using:
  • Windows: C:\Users\<user>\AppData\Local\nvim\init.lua
  • Linux: /home/<user>/.config/nvim/init.lua
Once we have created the init.lua file, we can add a configuration option to it for checking that Neovim is reading it correctly. For example, we can add a key mapping for quitting Neovim. In order to do so, we have to add the following line to the init.lua file:

vim.keymap.set('n', '<C-q>', vim.cmd.quit)

Then, we write and close the init.lua file, and start Neovim again. At this point, if we press Ctrl+q we should quit Neovim. Thus, confirming that Neovim is reading correctly the init.lua file.

After that, we can continue adding configurations to this init.lua file. But it is a good practice to split it into multiple files, as Neovim configuration system has support for modules. But that would be the topic for another post.

Popular posts from this blog

WebAssembly (Wasm): Fixing the Flaws of Applets

How to query Outlook from PowerShell