Development
Why Neovim is My Go-To Text Editor for Programming
People have their own text editor preferences for programming, and there are several text editors for each programming language, each with more functionality than the others. But at their core, they are all tools that allow users to create and edit plain text files or a variety of programming language files. Text editors differ from word processors because they do not add extra formatting information to the documents. For example, when you open a .doc file in a text editor, you’ll notice that most of the file is filled with formatting codes. Text editors, however, do not add formatting codes, which makes it easier to compile and debug your code.
Nowadays, everyone has their own programming setup based on their productivity level. If you’ve ever stumbled upon Instagram Programmers or coding influencers, you’ll notice that many of them have elaborate and visually appealing setups. But beyond the aesthetics, what truly matters is the efficiency and productivity of the tools they use. A programmer who spends most of their time coding usually has a favorite text editor that they find productive. However, people are often frustrated with software installations because they end up installing unnecessary software that takes up a lot of storage space. Some text editors can be heavy on the system, causing sudden freezing or crashes, which can be extremely unpleasant. This is why it’s crucial to choose lightweight and fast text editors for programming—tools that can boost productivity without weighing down your system.
For me, that tool is Neovim. I’ve set up Neovim to be as simple as possible, keeping only the essential plugins and keybindings. This makes it quick and distraction-free, which is important for staying focused during long coding sessions. The way Neovim works—allowing me to navigate and edit text with minimal hand movement—makes it incredibly efficient and boosts my productivity. Plus, the Lua configuration makes it easy to adjust and personalize as needed.
I also create my own remaps and option setups tailored to my workflow. This ensures I can work as efficiently and fast as possible, with everything exactly where I need it. For example, I’ve mapped common actions to specific keybindings, so I don’t have to reach for the mouse or remember complex commands. This level of customization is one of the reasons I love Neovim.
Another significant advantage of Neovim is its lightweight nature. With my minimalist setup, I can use Neovim on my MacBook Pro M1 for 10–15 hours without any issues. If I switch to other text editors or IDEs, I usually get only 7–9 hours of battery life. On my System76 Lemur Pro, Neovim easily lasts for 6–7 hours. The other editors and IDEs tend to make my laptop run hotter—so much so that I could probably cook chicken or rice with all that extra heat!
In this blog post, I’ll walk you through the process of installing Neovim on Linux, setting it up for programming, and customizing it to suit your workflow. Whether you’re a seasoned Vim user or new to modal editing, this guide will help you get started with Neovim and unlock its full potential.
Why Use Neovim?
Here are some reasons why Neovim stands out as a text editor for programming:
- Modern Architecture: Neovim is built with a more modern architecture, allowing for asynchronous processing. This means plugins can run in the background without blocking the editor, resulting in a smoother experience.
- Lua Integration: Neovim has first-class support for Lua, a lightweight and fast scripting language. This makes it easier to write and maintain configurations and plugins.
- Built-in LSP Support: Neovim comes with built-in support for the Language Server Protocol, which provides features like code completion, linting, and refactoring.
- Extensibility: Neovim is highly extensible, with a rich ecosystem of plugins and themes.
- Community-Driven: Neovim has a vibrant community that actively contributes to its development and maintenance.
- Lightweight: Neovim is incredibly lightweight compared to other text editors and IDEs, making it ideal for low-power devices or long coding sessions.
Prerequisites
Before we dive into the installation process, ensure that your system meets the following requirements:
- A Linux distribution (e.g., Ubuntu, Fedora, Arch Linux, etc.)
- A terminal emulator
- Basic knowledge of the command line
gitinstalled (for some installation methods)curlorwgetinstalled (for downloading files)
Installation Methods
There are several ways to install Neovim on Linux. We’ll cover the most common methods, including using package managers, building from source, and using pre-built binaries.
Installing Neovim via Package Managers
Package managers are the easiest and most convenient way to install software on Linux. Most Linux distributions have Neovim available in their official repositories.
Debian/Ubuntu-based Distributions
On Debian-based distributions like Ubuntu, you can install Neovim using the apt package manager.
-
Update the package list:
sudo apt update -
Install Neovim:
sudo apt install neovim -
Verify the installation:
nvim --versionThis command should display the installed version of Neovim.
Fedora
On Fedora, you can install Neovim using the dnf package manager.
-
Install Neovim:
sudo dnf install neovim -
Verify the installation:
nvim --version
Arch Linux
On Arch Linux and its derivatives, you can install Neovim using the pacman package manager.
-
Install Neovim:
sudo pacman -S neovim -
Verify the installation:
nvim --version
openSUSE
On openSUSE, you can install Neovim using the zypper package manager.
-
Install Neovim:
sudo zypper install neovim -
Verify the installation:
nvim --version
Installing Neovim from Source
If you want the latest version of Neovim or if your distribution’s package manager does not have an up-to-date version, you can build Neovim from source.
-
Install dependencies:
sudo apt install -y ninja-build gettext cmake unzip curl -
Clone the Neovim repository:
git clone https://github.com/neovim/neovim.git cd neovim -
Build and install Neovim:
make CMAKE_BUILD_TYPE=RelWithDebInfo sudo make install -
Verify the installation:
nvim --version
Installing Neovim via AppImage
AppImage is a format for distributing portable software on Linux without needing superuser permissions to install the application.
-
Download the Neovim AppImage:
wget https://github.com/neovim/neovim/releases/download/stable/nvim.appimage -
Make the AppImage executable:
chmod u+x nvim.appimage -
Run Neovim:
./nvim.appimageYou can also move the AppImage to a directory in your
PATHto make it accessible from anywhere:sudo mv nvim.appimage /usr/local/bin/nvim -
Verify the installation:
nvim --version
Installing Neovim via Snap
Snap is a package management system developed by Canonical. It allows you to install software in a sandboxed environment.
-
Install Neovim via Snap:
sudo snap install nvim --classic -
Verify the installation:
nvim --version
Post-Installation Setup
Now that Neovim is installed, let’s set it up to make it more powerful and user-friendly.
Basic Configuration
Neovim’s configuration files are stored in ~/.config/nvim/. The main configuration file is init.vim, which is written in Vimscript. However, Neovim also supports Lua for configuration, which is more modern and flexible.
-
Create the configuration directory:
mkdir -p ~/.config/nvim -
Create the
init.vimfile:touch ~/.config/nvim/init.vim -
Edit the
init.vimfile:nvim ~/.config/nvim/init.vimAdd some basic settings to get started:
" Enable line numbers set number " Enable syntax highlighting syntax on " Enable mouse support set mouse=a " Set tab width to 4 spaces set tabstop=4 set shiftwidth=4 set expandtab
Installing Plugins with a Plugin Manager
Neovim has a rich ecosystem of plugins that can enhance its functionality. One of the most popular plugin managers is vim-plug.
-
Install
vim-plug:sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' -
Configure
vim-plugininit.vim:call plug#begin('~/.local/share/nvim/plugged') " Add plugins here Plug 'preservim/nerdtree' " File explorer Plug 'neoclide/coc.nvim', {'branch': 'release'} " Intellisense engine call plug#end() -
Install the plugins: Open Neovim and run the following command:
:PlugInstall
Setting Up the Language Server Protocol (LSP)
Neovim has built-in support for the Language Server Protocol (LSP), which provides features like code completion, linting, and refactoring.
-
Install a language server: For example, to install the Python language server:
pip install python-language-server -
Configure the LSP in
init.vim:lua << EOF local nvim_lsp = require('lspconfig') nvim_lsp.pylsp.setup{} EOF -
Test the LSP: Open a Python file in Neovim and check if code completion and linting are working.
Exploring Neovim Features
Neovim comes with several powerful features that set it apart from traditional text editors.
Built-in Terminal
Neovim has a built-in terminal that allows you to run shell commands without leaving the editor.
-
Open the terminal:
:terminal -
Exit the terminal: Press
Ctrl+\followed byCtrl+nto return to normal mode, then type:qto close the terminal.
Asynchronous Processing
Neovim’s asynchronous processing allows plugins to run in the background without blocking the editor. This is particularly useful for tasks like linting, formatting, and running tests.
Lua Integration
Neovim has first-class support for Lua, making it easier to write and maintain configurations and plugins. You can use Lua to create custom keybindings, define functions, and more.
Conclusion
Neovim is a powerful and modern text editor that offers a wide range of features for developers. Whether you’re a seasoned Vim user or new to modal editing, Neovim provides a highly customizable and efficient environment for coding.
In this guide, we covered multiple methods for installing Neovim on Linux, including using package managers, building from source, and using pre-built binaries. We also explored how to configure Neovim, install plugins, and set up the Language Server Protocol.
With its modern architecture, Lua integration, and built-in LSP support, Neovim is an excellent choice for developers looking to enhance their productivity. Give it a try, and you might find that it becomes an indispensable tool in your development workflow.
Happy coding! 🚀