Configuring NeoVim plugins
Tags: neovim, nvim
Published: 2022-08-04 05:37:40

[NeoVim](https://neovim.io/) is a fork of vim that evolved into its own thing, but maybe you already knew that.

In this very short post, I'm going to help you configure your NeoVim installation on Windows to use [NERDTree](https://github.com/preservim/nerdtree) and [vim-airline](https://github.com/vim-airline/vim-airline).

## Starting from ready-made `init.vim` file

Download Lefticus's [vim-config](https://github.com/lefticus/nvim-config) files (including the `autoload` directory) to your nvim configuration directory.

On Windows 10 it will be located at `C:\Users\<USER>\AppData\Local\nvim`, where `<USER>` is your user handle. Maybe you'll need to create the nvim folder.

Lefticus's config files already include vim-airline. Let's add NERDTree. Locate in the `init.vim` file the section where plugins are added. Add the line `Plug 'preservim/nerdtree'` to this section. You may end with something like this.

![Section of the init.vim file with Plug commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eoqz9lnjyrtiow0b0jt7.png)

## Installing the plugins

Launching neovim after adding the files may show some errors. These errors will be corrected after downloading the plugins.

Enter command mode (press `:`) and run the command `PlugInstall`. Ex: `:PlugInstall`. Another tab will open with the downloading and installation progress.

If at any moment you need to update the plugins, run `:PlugUpdate`. And if any plugin is broken (for example, when I changed the path to NERDTree), you may be prompted to run `:PlugClean`.

## Configuring Airline to use a Nerd Font with Powerlines

Firstly, if you don't have a Nerd Font, you can install [Cascadia Code](https://github.com/microsoft/cascadia-code).

Better yet, if you're using the [vim-devicons](https://github.com/ryanoasis/vim-devicons) plugin, use the patched version at [Nerd Fonts](https://github.com/ryanoasis/nerd-fonts) that include the icons. The rest of the post follows as equal.

The next step is to add a line to your `init.vim` file configuring GUI Font to a font with powerlines. See the example below, where I configure neovim to use Cascadia Mono PL with size 12:

```
set guifont=Cascadia\ Mono\ PL:h12
```

## Mapping an shortcut for toggling NERDTree

Add the following line to your `init.vim` file.

```
map <C-o> :NERDTreeToggle<CR>
```

This will set `Ctrl+o` to run the command `:NERDTreeToggle`.

## Adjusting tabs to spaces

These lines will adjust tabs to 4 charactes wide. (Extracted from [StackOverflow](https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces)).

```
set tabstop=4
set softtabstop=0 noexpandtab
set shiftwidth=4
```

## Being a heretic and using the mouse

If you really want to use the mouse with neovim, add `set mouse=a` to your `init.vim`. `a` stands for "all modes".

Beware! You will attract strange looks from fellow workers using a mouse with neovim.

## The final look

![NeoVim screen showing what you can achieve using the plugins and config files mentioned in the post](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u7q53a8ln6fhclbbby0.PNG)

## References

- [C++ Weekly with Jason Turner](https://www.youtube.com/c/lefticus1) - From where I took the initial vim files. Jason is a well known figure in the C++ community, and his channel is a great place to learn.
- [How to make a pretty prompt in Windows Terminal with Powerline, Nerd Fonts, Cascadia Code, WSL, and oh-my-posh](https://www.hanselman.com/blog/how-to-make-a-pretty-prompt-in-windows-terminal-with-powerline-nerd-fonts-cascadia-code-wsl-and-ohmyposh) - Scott guides you through configuring Windows Terminal to show git status on your prompt. Still useful, and where I first heard about Nerd Fonts.