How to start using Neovim in 2023
Learn about Neovim modes, navigation and how to create your first config
Neovim is a powerful and highly customizable text editor that is well-suited for a wide range of programming and text editing tasks. If you are looking for a fast and reliable text editor, Neovim is definitely worth considering.
However, using it may prove to be challenging, especially for new users. But once you learn the keyboard shortcuts and commands, and the muscle memory kicks in, you will be able to navigate your codebase in a much more efficient way. You will never look back, I promise.
So, where to start? Counterintuitively, we will not start by installing Neovim.
Neovim integration for your IDE
The best way to start learning Neovim is to use it inside your IDE of preference.
If you're a user of VS Code, you may use one of the following extensions:
If you're a JetBrains user here is a plugin for you:
After installing the extensions, follow the instructions for the plugin you choose.
Now, you will notice that something has changed in your editor. You can no longer write text in the file that is opened.
That's because you're in a Normal mode of vim. What does it mean?
Learn about (Neo)Vim modes
Basically, vim introduces a few modes that will change the default behaviour of the text editor. Each of the modes serves a specific purpose.
Normal mode: This is the default mode in Neovim, and it is used for entering commands and navigating the editor.
Insert mode: This mode is used for inserting and editing text. To enter insert mode, you can press the "i" key, or use the ":insert" command.
Visual mode: This mode is used for selecting and manipulating text. To enter visual mode, you can press the "v" key, or use the ":visual" command.
Command-line mode: This mode is used for entering Ex commands, which are special commands that can be used to perform various tasks in Neovim. To enter command-line mode, you can press the ":" key, or use the ":command-line" command.
Terminal mode: This mode is used for running terminal commands within Neovim. To enter terminal mode, you can press the "F9" key, or use the ":terminal" command.
You can press the <ESC> key to go back to Normal mode.
Each of these modes has its own set of commands and behaviours, and it is important to understand how they work in order to use Neovim effectively.
Learn how to navigate
Vim offers a set of keyboard shortcuts to allow quick navigation.
Some of the basic keybindings that you need to learn include:
h
,j
,k
,l
: These keys allow you to move the cursor left, down, up, and right, respectively. (arrows can be used too)w
: Move the cursor to the beginning of the next word.b
: Move the cursor to the beginning of the previous word.e
: Move the cursor to the end of the current word.0
(zero): Move the cursor to the beginning of the current line.$
: Move the cursor to the end of the current line.gg
: Move the cursor to the beginning of the file.G
: Move the cursor to the end of the file.{
: Move the cursor to the beginning of the previous paragraph.}
: Move the cursor to the beginning of the next paragraph.Ctrl + f
: Scroll down one page.Ctrl + b
: Scroll up one page.Ctrl + d
: Scroll down half a page.Ctrl + u
: Scroll up half a page.
It's also helpful to know that you can use a number before some of these commands to repeat the action many times. For example, typing 3w
will move the cursor to the beginning of the third word after the current cursor position.
After learning how to navigate in vim, it's time to create your first neovim config.
Installing neovim locally
Instructions on how to install neovim can be found here: https://github.com/neovim/neovim/wiki/Installing-Neovim
But, for most of us, a simple installation with a package manager will be enough.
Installation on Windows
For widows you can use chocolatey:
choco install neovim
Installation on OSX
On OSX Neovim can be installed using Homebrew:
brew install neovim
Installation on Linux
Ubuntu
sudo apt install neovim
Other Debian-based distributions
sudo apt-get install neovim
Arch Linux
sudo pacman -S neovim
Now that we have neovim installed, let's configure it.
Creating your first config
Creating a neovim config from scratch can be an intimidating task. That's why it's a good idea to use a kickstart config prepared by the neovim team.
It can be found here: https://github.com/nvim-lua/kickstart.nvim
The kickstart config offers a set of the most useful plugins, as well as sane defaults. Everything can be changed later, as you learn how to adjust it to your needs.
By just following the install instructions from this repository you can turn your old boring vim editor into a full-blown IDE.
Keep on practising
You will probably need some time to feel comfortable with vim. For me, it took me a few days. But right now I'm suffering whenever I need to use an editor that doesn't support vim mode.
In time, you will be able to extend your config, install new plugins and remove some that you don't use. Maybe you will change some of the default keybindings offered by the config. Don't be afraid to try new things, but remember, to always have a backup. I'm hosting my neovim config on GitHub so that I can always revert to the previous versions.
I'm curious to see what your config looks like. If you have it on GitHub, feel free to share it with me :)
Did you find this article valuable?
Support Krzysztof Kałamarski by becoming a sponsor. Any amount is appreciated!