Skip to main content
  1. Posts/

My Neovim Configuration Setup Guide

·1181 words·6 mins
lua neovim
Table of Contents
My Neovim Configuration - This article is part of a series.
Part 1: This Article

Introduction
#

This article is a walkthrough on how to configure my neovim setup. My setup has been configured for working with Javascript, React, Python, Golang, and Java.

Screenshots
#

Editor

Diff View

Git Graph

Debugging

Todo

Features
#

Prerequisites
#

Terminal Emulators
#

The terminal emulator you choose to use greatly affects the appearance and features on Nvim. Since Nvim supports true colors, terminals that supports true colors are preferred.

For a list of terminals that support true colors, see here

Patched Fonts
#

Some plugins often use Unicode symbols that are not available in normal fonts, you need to install a patched font from the nerd-fonts project.

Dependencies
#

1. Ensure Neovim v0.9+:
#

Ensure that you have Neovim version 0.9 or above installed. Check your Neovim version using:

nvim --version

2. Python
#

A lot of Nvim plugins are mainly written in Python. Install python3 from python.org and ensure that typing python --version outputs Python 3.x. by adding python alias on your .bashrc or .zshrc:

alias python=python3

3. Install python3-venv:
#

Install the python3-venv package using the following command:

sudo apt install python3-venv

4. pynvim Package:
#

Install the pynvim package using pip:

python3 -m pip install -U pynvim

5. Node:
#

To install node.js, you can use binaries from nodejs.org or Node Version Manager nvm. I personally prefer using nvm as it allows you to quickly install and use different versions of node.

Install nvm using either cURL or Wget:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Running either of the above commands runs a script that downloads nvm and sets up nvm source lines on your correct profile file (.bash_profile, .zshrc, .profile, or .bashrc )

Reload the shell configuration. Replace .zshrc with your shell configuration file:

source ~/.zshrc

Install the latest node version using the following command:

nvm install latest

6. Node Packages:
#

Install yarn, neovim and tree-sitter node packages by running the following command:

npm i -g yarn neovim tree-sitter

7. Telescope requirements:
#

For telescope to work without any issues, you need to have both ripgrep and fd packages. Install them using:

sudo apt install ripgrep fd-find

8. Optional: For GoDevs:
#

If you haven’t installed Go, use the official installation guide on how to go about it.

After installation, set up the required environment variables in your shell configuration file (e.g., .bashrc or .zshrc):

export GOPATH=~/go
export GOROOT=/usr/local/go
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:~/go/bin

Install Go Language Server (gopls) with the following command:

go install golang.org/x/tools/gopls@latest

9. Optional: Java
#

For Java developer, follow the following steps:

  • Ensure you are running JRE 17 and above
    java --version
    
  • Ensure JAVA_HOME environment variable points to the JDK directory. Identify the correct path using:
    sudo update-alternatives --config java
    
    Set JAVA_HOME in your .bashrc or .zshrc:
       export JAVA_HOME=/path/to/openjdk
    
    For example:
    export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
    
  • Download and extract a snapshot build from http://download.eclipse.org/jdtls/snapshots/ using:
    wget https://download.eclipse.org/jdtls/snapshots/jdt-language-server-1.31.0-202312211634.tar.gz && sudo tar -C /usr/local -xzf jdt-language-server-1.31.0-202312211634.tar.gz
    

10. Clone Configuration Repo:
#

Clone my Neovim configuration repository to ~/.config/nvim:

git clone https://github.com/justicenyaga/my_nvim_config.git ~/.config/nvim

11. Optional: win32yank for WSL
#

For WSL users, install win32yank for clipboard interaction between Windows and WSL by following these steps:

  1. Download win32yank binary:

  2. Copy it to /usr/local/bin:

    • After downloading the binary, copy it to the /usr/local/bin directory.
  3. Add execution permissions:

    • Set execution permissions for win32yank.exe using the following command:
      chmod +x win32yank.exe
      
  4. Uninstall xclip and xsel:

    • To avoid potential conflicts, uninstall xclip and xsel if they are installed on your system as they would be used by default.
      sudo apt remove xclip
      sudo apt remove xsel   # if it exists
      

These steps ensure the proper installation and configuration of win32yank as the default clipboard tool, avoiding conflicts with xclip and/orxsel.

Neovim Plugin Installation
#

1. Open Neovim:
#

nvim

2. Allow the plugins to load.
#

Wait for the plugins to download. Once the plugins are installed, issue the command :Mason to view the progress of LSPs, linters, formatters, and debuggers installations.

Once everything has been installed, exit neovim and carry on with further configurations.

3. Language Servers Customizations:
#

To add more language servers and debug adapters to the ones I’ve configured, check out the lsp server, linters, formatters and debug adapter configuration guides.

You can use Mason (opened with the command :Mason) to seamlessly install the configured servers. You can also use Mason to ensure certain servers, formatters, linters, and DAPs are installed. Check out the mason-lspconfig, mason-tool-installer and mason-nvim-dap configuration guides for more information on this.

4. Language Parsers Customizations:
#

I’ve employed nvim-treesitter to customize language parsers. Explore their list of supported languages. To integrate a new language parser, just include it in the ensure_installed object within the nvim-treesitter configuration file (~/.config/nvim/lua/justice/plugins/nvim-treesitter.lua). Treesitter will handle the automatic installation of parsers specified in the ensure_installed section.

5. Optional: Copilot auto-completion
#

  • To use copilot auto completion, you need to have a github copilot subscription.
  • Authenticate to Copilot using :Copilot auth command.

6. For Java Developers:
#

Download and setup the java-debug extension. Install it on your neovim data folder ~/.local/share/nvim using the following commands:

git clone https://github.com/microsoft/java-debug.git ~/.local/share/nvim/java-debug
cd ~/.local/share/nvim/java-debug
./mvnw clean install

7. For WSL users:
#

Uncomment the wsl clipboard block on ~/.config/nvim/lua/justice/core/options.lua if you are using WSL.

vim.g.clipboard = {
  name = "win32yank-wsl",
  copy = {
    ["+"] = "win32yank.exe -i --crlf",
    ["*"] = "win32yank.exe -i --crlf",
  },
  paste = {
    ["+"] = "win32yank.exe -o --lf",
    ["*"] = "win32yank.exe -o --lf",
  },
  cache_enabled = true,
}

Conclusions
#

That’s it! Your Neovim environment is now configured and ready for use. Customize further based on your preferences, and happy coding!

Navigate to the next article in this series via the blue drop-down list at the end/beginning of this page for a detailed walkthrough of the keymaps configured in my Neovim setup.

Recommendations
#

Congratulations on setting up your Neovim environment! If you’re looking to further enhance your terminal experience, I highly recommend checking out my tmux configuration post linked below. Tmux is a powerful terminal multiplexer that allows you to organize and manage multiple terminal sessions effortlessly.

My Tmux Configuration
·323 words·2 mins
tmux neovim

Happy coding!

My Neovim Configuration - This article is part of a series.
Part 1: This Article