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 #
Features #
- Plugins managed with lazy.nvim
- Syntax highlighting with treesitter
- Code snippets and code auto-completion via nvim-cmp
- LSPs installed with Mason and configured using lspconfig
- Code formatting with conform
- Debuggers installed and configured with nvim-dap
- Terminal integration with fterm
- Fuzzy searching with telescope
- Easily and quickly navigate to frequently used files with harpoon2
- Preview markdown files with markdown-preview.nvim
- Git decorations to reflect changes in files using gitsigns.nvim
- Git integration via fugitive
- Git branch/commit/diff viewing via diffview
- User-defined mapping hint via which-key.nvim
- Beautiful and powerful git graph via vim-flog
- Identation guides via ident-blankline.nvim
- Rainbow delimiter pairs via rainbow-delimiters.nvim
- Code Runner via code_runner.nvim
- copilot AI suggestions
- friendly-snippets and VS Code ES7 snippets
- Faster code commenting with Comment.nvim
- Quicky add/delete/replace/find/highlight delimiter pairs (quotes, brackets, etc) with mini.surround
- Fold management with nvim-ufo
- Todo comments via todo-comments.nvim
- Beautiful status bar via lualine
- Beautiful cmdline and popupmenus from noice.nvim
- tokyonight colorscheme
- nvim-tree file explorer with nvim-web-devicons for the icons
- Beautiful UI via dressing.nvim
- Animated GUI notifications via nvim-notify
- Tabs and Splits navigation via vim-tmux-navigator
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:Setsudo update-alternatives --config java
JAVA_HOME
in your.bashrc
or.zshrc
:For example:export JAVA_HOME=/path/to/openjdk
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:
-
Download win32yank binary:
- Visit
https://github.com/equalsraf/win32yank/releases to download the
win32yank
binary.
- Visit
https://github.com/equalsraf/win32yank/releases to download the
-
Copy it to
/usr/local/bin
:- After downloading the binary, copy it to the
/usr/local/bin
directory.
- After downloading the binary, copy it to the
-
Add execution permissions:
- Set execution permissions for
win32yank.exe
using the following command:chmod +x win32yank.exe
- Set execution permissions for
-
Uninstall
xclip
andxsel
:- To avoid potential conflicts, uninstall
xclip
andxsel
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
- To avoid potential conflicts, uninstall
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!
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.
Happy coding!