How to start using Neovim in 2023

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'll observe a noticeable change in your editor. Writing text in the open file is no longer possible.

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.

  1. Normal mode: This is the default mode in Neovim, and it is used for entering commands and navigating the editor.

  2. 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.

  3. 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.

  4. 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.

  5. 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 mode in Neovim features unique commands and behaviours, so mastering their functions is crucial for utilizing the program efficiently.

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:

  1. h, j, k, l: These keys allow you to move the cursor left, down, up, and right, respectively. (arrows can be used too)

  2. w: Move the cursor to the beginning of the next word.

  3. b: Move the cursor to the beginning of the previous word.

  4. e: Move the cursor to the end of the current word.

  5. 0 (zero): Move the cursor to the beginning of the current line.

  6. $: Move the cursor to the end of the current line.

  7. gg: Move the cursor to the beginning of the file.

  8. G: Move the cursor to the end of the file.

  9. {: Move the cursor to the beginning of the previous paragraph.

  10. }: Move the cursor to the beginning of the next paragraph.

  11. Ctrl + f: Scroll down one page.

  12. Ctrl + b: Scroll up one page.

  13. Ctrl + d: Scroll down half a page.

  14. 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 configuration provides a collection of highly useful plugins and sensible default settings. As you become more familiar with customization, you can modify everything to suit your preferences.

Simply follow the installation instructions from this repository to transform your dull vim editor into a powerful, feature-rich IDE.

Keep on practising

It may take some time for you to become comfortable with Vim. Personally, it took me a few days. Now, I find it difficult to use an editor that doesn't support Vim mode.

Over time, you'll be able to expand your configuration, add new plugins, and remove ones you no longer need. You might even modify some of the default keybindings provided by the config. Don't hesitate to experiment, but always keep a backup handy. I host my Neovim configuration on GitHub, allowing me to easily revert to previous versions if needed.

I'm eager to check out your configuration. If it's on GitHub, don't hesitate to share it with me :)

Did you find this article valuable?

Support Krzysztof Kałamarski by becoming a sponsor. Any amount is appreciated!