Effective Neovim Setup. A Beginner’s Guide
Tags: vim, beginners, neovim
Published: 2024-03-09 14:53:03

Vim is a text editor that comes preinstalled with most major Linux distributions. It’s a highly customizable editor and it can be a productivity improvement for developers when utilized well.

Vim encourages the use of keyboards with several keybindings that can operate differently in different modes thereby minimizing the need for a mouse. 

Simply put, Vim is an editor that can match the speed at which you think.

Neovim is an extension of Vim. It’s built for users who want the good parts of Vim, and more.

You can read more about the vision of Neovim [here](https://neovim.io/charter/).

Note: For the article, we are using [LazyVim](http://www.lazyvim.org/) to configure our Neovim setup. LazyVim makes it easy to customize and extend Neovim’s configuration.

## Installing Neovim

There are several ways to install Neovim. This [wiki](https://github.com/neovim/neovim/blob/master/INSTALL.md) provides several guidelines on how to install Neovim. 

I use an Arch Linux machine so it was easy to install Neovim by running the command:

```bash
sudo pacman -S neovim
```

On a Windows machine, you can use [Chocolatey](https://chocolatey.org/) by running the command.

```bash
choco install neovim
```

On a macOS machine, you can use [homebrew](https://brew.sh/) by running the command.

```bash
brew install neovim
```

Once Neovim is installed, we can confirm that it exists by running the command.

```bash
neovim
```

The output should look similar to the image below.
![basic neovim](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hchx3xng3ju60ds4tlt4.png)

## Setting up LazyGit

There are some requirements needed to set up LazyVim:

- Neovim (we have this installed already)
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- a [Nerd Font](https://www.nerdfonts.com/) (optional but needed to display icons)

First, we will clone the LazyVim starter repository into our  Neovim runtime path.

`~/.config/nvim` is the Neovim’s runtime path for macOS and Linux machines while `~/AppData/local/nvim` is for Windows machines. 

Since I am not an Arch Linux machine, I’d run the command below:

```bash
git clone https://github.com/LazyVim/starter ~/.config/nvim
```

Run the command `nvim` again to confirm that it is set up.

![lazyvim-basic](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrxnkixmcj8n2gi1hotq.png)

## Basic Plugins Installation

LazyVim comes with a wealth of plugins pre-configured and ready to use. This section of the article will introduce two more plugins that can greatly improve your Neovim experience.

### **nvim-telescope**

This is a highly extendable fuzzy finder over lists. To install this plugin, you can create a new file in the `plugins` directory of your Neovim config path named `telescope.lua`

```bash
cd ~/.config/nvim/lua/plugins/; nvim telescope.lua
```

Then paste the code below into the `telescope.lua` file

```lua
--telescope.lua
return {
  "nvim-telescope/telescope.nvim",
  tag = "0.1.5",
  dependencies = { "nvim-lua/plenary.nvim" },
}
```

Then in `~/.config/nvim/lua/config/lazy.lua` you can add this below the last line.

```lua
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<C-p>', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
```

The code above set up keymaps to execute some of the functions provided by nvim-telescope.

The `<C-p>` keymap is a `Ctrl + p` keybinding that opens a fuzzy finder for files in a modal.

![treesitter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0fnolox6p83qla98snw.png)

### **nvim-treesitter**

This is a plugin that provides a simple way to use the [tree-sitter](https://github.com/tree-sitter/tree-sitter) in Neovim and also provides functionalities like highlighting, etc.

Just like we did for the nvim-telescope plugin, we will create a new file in the `plugins` directory of Neovim’s configuration called `treesitter.lua` and then paste the code below into it.

```lua
-- treesitter.lua
require("lazy").setup({{
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function () 
      local configs = require("nvim-treesitter.configs")

      configs.setup({
          ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html" },
          sync_install = false,
          highlight = { enable = true },
          indent = { enable = true },  
        })
    end
 }})
```

The `ensure-installed` is a tuple that includes various languages you want to include the parser support for. 

You can see a list of supported languages [here](https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#supported-languages).

## Conclusion

This is a very basic introduction to getting Neovim set up quickly.

Using Neovim can be very uncomfortable for the first time especially when you have habits that is different from from what Vim preaches. It will be a slow painful start but in no time, you will pick it up. 

And do not be overwhelmed with trying to learn everything about Vim for a start. Pick up the barest minimum you need to get started and grow with that.