How To Use Neovim: A Comprehensive Introduction
Enhance Text Editing Aesthetics on Terminals with Neovim
After learning to write codes with Vim on a Linux distribution terminal, I often wondered how to make my text editor visually appealing.
I discovered Neovim thanks to a friend. Since then, I've been amazed by what Neovim can do and its endless possibilities.
This article will guide you in comprehending Neovim's role in programming, its advantages, plugins, and additional tips for effectively utilizing Neovim.
What is Neovim?
Neovim, also known as Nvim, is a highly extensible text editor well-suited for terminal-based text editing tasks. It inherits many features from its predecessor, Vim, while adding enhancements and improving usability.
Brief Evolution
In the early 1990s, Bram Moolenaar created Vim (Vi Improved). It inherits most commands from the Unix program 'Vi' and introduces numerous additional commands.
Vi is pronounced as ‘vee-eye,’ Vim is pronounced as one word like Him, while Nvim is ‘en-vim.’
Thiago de Arruda initiated the development of NeoVim in 2011 as a fork of Vim.
The creation of Neovim aimed to overcome Vim's limitations, such as difficulty in extending and customizing the text editor. Neovim has evolved into a robust and adaptable text editor.
Benefits of using Neovim
Benefits of using Neovim include:
It is well known for its speed and efficiency in executing commands and text editing.
Thanks to the plugin systems, users can customize their editing environment to suit their workflow.
Users can navigate and select files through the built-in terminal emulator without leaving the text editor.
Neovim works smoothly with version control systems like git, making it easy for users to manage their code repository without leaving the text editor.
It assists users in code completion by identifying errors in codes when writing programs like JavaScript, HTML, CSS, and others.
The benefits of using Neovim are too numerous to mention, so let’s get started!
Prerequisite
Basic Understanding of Programming or Scripting Experience
Basic Knowledge of Text Editing
Basic Knowledge of a Command Line Interface (CLI)
Most importantly, the willingness to learn and explore
Best used with JetBrainsMono Nerd Font and Ubuntu
Installing Neovim
Neovim is available for Windows, MacOS, Linux, and other systems.
On Windows OS, it is advisable to use Ubuntu via the Windows Subsystem for Linux (WSL).
Check here for five easy steps in setting up Ubuntu on Windows.
After downloading JetBrainsMono Nerd Font, navigate to Windows terminal > settings > defaults > appearance > font face and select JetBrainsMono Nerd Font.
Install
To install Neovim, proceed to your terminal and run the following command:
# for Ubuntu-based systems/Linux
sudo apt update
sudo apt upgrade
sudo apt install neovim
If you use Homebrew on macOS, you can install Neovim with the following command:
# for macOS using homebrew
brew install neovim
If you are using the Chocolatey package installer on Windows PowerShell, you can install Neovim with the following command:
#for Windows Powershell
choco install neovim
Note that the installation process might differ slightly depending on the type of distribution and package manager you have installed. Always ensure your package manager is up-to-date before installing software to ensure you get the latest version of Neovim.
Configure
Neovim has numerous configurations and can take a long time to set up manually.
After thorough research, I found a Neovim configuration that is easy to install and available to all called AstroNvim on Git Hub.
To install the config, clone this Git Hub repo:
#copy and paste into your terminal
git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim nvim
Installing this configuration takes a lot of time and patience. Upon successfully installing the configuration, use the command nvim
to launch Neovim in the terminal.
Navigation the User Interface (UI)
The user interface in Neovim after installing plugins stands out as one of the most aesthetically pleasing interfaces among numerous text editors.
Making it easy to navigate the terminal, edit files, smoothly run version controls, and customize the coding environment.
Basic Text Editing
In Neovim, you can improve fundamental text editing and elevate code completion with the help of plugins and configuration settings.
To open a file with Neovim use the command nvim
+ <filename>
.
Above is a code snippet illustrating code completion using the Language Server Protocol (LSP).
When navigating the user interface, we consider the following modes:
Normal Mode: This is the default mode after launching Neovim.
Insert Mode: Use
i
to activate this mode and start typing. UseEsc
to go back to normal mode.Visual Mode: Use
v
or left-click anywhere on the screen to activate the visual mode, where users can copy text from the terminal to external applications.Command-line Mode: in Normal Mode, use
:
to enter Command-line Mode, where you can enter various commands. For example,:wq!
Saving and Quitting
To quit Neovim, use :q
or <leader>
+ q
.
Use :w
or <leader>
+ w
to save changes made to the file.
To discard changes, use :q!
(It forcefully quit without saving).
To save and quit, use :wq
.
Tips and Tricks
Install Language Server Protocol (LSP): It is a tool for reporting warnings and code errors, code completion, syntax checking, code formatting, and hover information.
To install LSP, run this command in command-line mode:
LspInstall
followed by the server name you want to install.
For example: LspInstall pyright
or LspInstall clang
For Language Parser:
Run the command :TSInstall
followed by the name of the language you want to install.
Example: :TSInstall python
Some Extra Tips:
Run the command :AstroUpdate
for plugin updates.
Run the command :ToggleTerm
to open the in-built terminal.
Run the command :Neotree
or <leader>
+ e
for a tree-like file explorer.
Use |
(pipe symbol) to split the screen vertically.
Use \
(backslash) to split the screen horizontally.
Run the command <leader>
+ ff
to open a file search buffer.
Note: The Spacebar key is called the leader key.
Also note that most of these tips and tricks are specifically for AstroVim plugins and may not work with the default Neovim settings.
These plugins enable users to open multiple files without exiting the text editor.
To uninstall Neovim from the terminal:
sudo rm /usr/local/bin/nvim
sudo rm -r /usr/local/share/nvim/
Conclusion
In summary, Neovim stands as a versatile and powerful text editor, inheriting the strengths of Vim while addressing its limitations.
Its open-source nature, extensive plugin support, and dedicated community make it a top choice for developers seeking a flexible and efficient text editing experience while still beautifying their coding environment.
Resources and Credits
Gratitude to the following repositories, plugin authors, and the Neovim community for making this article possible:
AstroNvim (source)
fr4nkln11 (Franklin Ikeh) · GitHub (inspired by)
Kindly visit Neovim, AstroNvim, and NvChad for more resources.
Happy coding!