Menu

Easiest Neovim Setup (Configuration)

Taufik Nurhidayat
4 min read
#tutorial #programming
social_cards/neovim_setup_lzc1ck.png

Neovim is one of several text editors out there, especially those often used for programming/coding. However, some configuration is needed first to make neovim a powerful code editor.

Requirements

Before we configure neovim, there are several requirements needed for our configuration to run smoothly.

  1. Neovim
    Of course we need neovim itself, you can install it based on the operating system you use. Make sure you install the latest version of neovim, at least 0.9.5.

  2. Terminal with GPU Rendering
    Terminal with gpu rendering is optional but recommended because it can improve neovim performance, examples are Kitty and Alacritty terminals.

  3. Nerd Font
    To maximize our neovim display, install Nerd Fonts and set your terminal with fonts that have been patched with nerd fonts.

  4. Clang/GCC
    Clang/GCC is a compiler for C language, you are recommended to install it.

  5. Git
    We need git to clone the available config repository.

  6. NPM
    NPM is very necessary when we will install syntax highlighter and lsp, so it is highly recommended to install it.

Besides these requirements, I highly recommend you install some other requirements such as:

  • tree-sitter
  • python, pip, pynvim
  • xsel (clipboard tools for linux)

Neovim Configuration Steps

1. Backup Old Configuration Files

If you have configured neovim, you should backup it first. If on linux/mac, you can use the following command:

mv ~/.config/nvim{,.bak}

For windows users, use the following command:

Move-Item $env:LOCALAPPDATA\nvim $env:LOCALAPPDATA\nvim.bak

2. Install LazyVim

Yes, for easy neovim configuration we will use what is already available. And in this tutorial, we use LazyVim. Use the following command to clone the lazyvim configuration file to your computer:

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

or if windows user:

git clone https://github.com/LazyVim/starter $env:LOCALAPPDATA\nvim

Delete the git directory in the neovim configuration folder earlier, with the following command:

# linux/macos
rm -rf ~/.config/nvim/.git

# windows
Remove-Item $env:LOCALAPPDATA\nvim\.git -Recurse -Force

3. Run Neovim

Now, we have to run neovim with the nvim command on the terminal you use. Wait for the installation process to complete, if an error occurs in the process you can exit neovim first with the command :qa and reopen neovim.

Besides that, you can also check if errors still occur with the command :LazyHealth, which of course is done on neovim.

4. LSP Configuration

To make neovim powerful, we have to install LSP (Language Server Protocol). That way, our text editor is able to diagnose errors, automatic completion, navigate to definitions and other things depending on the lsp itself.

You also need to pay attention, lsp for what language you will use. For example, if I use typescript and rust programming languages, then I will install typescript-language-server and rust-analyzer. Besides that, there are two ways to install lsp on lazyvim, namely via command and file configuration from Mason plugin.

Install LSP Via Command

This method is relatively easier, but when you use this configuration on another computer, you have to repeat this command. To do this, use the command :MasonInstall <lsp-name>, here’s an example:

:MasonInstall typescript-language-server rust-analyzer

Install LSP Via Configuration File

Although using configuration files is quite complicated, it has advantages such as when we use configurations on other computers, we just need to use this configuration. The way is to open the neovim configuration folder in terminal with the command:

cd ~/.config/nvim

If you are a windows user you can use its own command, as I remember you can use the following command.

dir $env:LOCALAPPDATA\nvim

then create a new file in the ./lua/plugins folder with the filename mason.lua or you can directly use neovim with the following command:

nvim lua/plugins/mason.lua

Then paste the following code in the file:

return {
  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "stylua",
        "json-lsp",
        "shellcheck",
        "shfmt",
        "flake8",
        "rust-analyzer",
        "typescript-language-server",
        "tailwindcss-language-server",
        "prettier",
        "prettierd",
        "svelte-language-server",
      },
    },
  },
}

You can also change the configuration, such as adding other lsp or removing unnecessary lsp. Please save the file with the command :w.

Restart neovim with the command :qa, so that the configuration file runs.

5. Syntax Highlighter Configuration

To provide good highlighting on the written code, we have to install the tree-sitter plugin. Same as Mason, this plugin can also be used in two ways, namely command and config file.

Install Highlight Via Command

:TSInstall typescript tsx rust

Install Highlight Via Configuration File

Create a new file in the lua/plugins/treesitter.lua folder, then you can paste the following code.

return {
  "nvim-treesitter/nvim-treesitter",
  opts = {
    ensure_installed = {
      "bash",
      "html",
      "css",
      "javascript",
      "json",
      "lua",
      "markdown",
      "markdown_inline",
      "python",
      "query",
      "regex",
      "tsx",
      "typescript",
      "vim",
      "yaml",
      "svelte",
      "astro",
    },
  },
}

You can also change or add any programming language in the configuration file. Don’t forget to save it and restart neovim again, so that this file configuration runs.

Final Words

Although a bit complicated, this is the easiest way I know. Besides that, to maximize the use of lazyvim configuration, it is recommended to know the shortcuts or keymaps available on the lazyvim documentation page itself.

You can also find my neovim configuration on the github page https://github.com/fiik346/nvim-config, of course you can clone and use it freely.