coc.nvim Language Server with Neovim
After writing the last blog on how to setup a Linux Kernel Development environment, I realized I haven’t written how I’ve setup Neovim with coc.nvim in NixOS.
What is Neovim
Neovim is a powerful and extensible text editor. Neovim is a fork of Vim7. One of its strengths is its support for plugins that enhance its functionality. Coc.nvim is one such plugin that brings powerful language server protocol (LSP) support to Neovim, making it an excellent choice for programming and text editing tasks.
Neovim in NixOS
First, we list neovim
as one of the packages, eg.
1
2
3
4
5
6
7
8
{
# ...
environment.systemPackages = with pkgs; [
# ...
nodejs
];
# ...
}
If you would like to get clangd
, rust-analyzer
, and java
language server, remember to add the following:
1
2
3
clang_16
clang-tools_16
jdk
Neovim Configurations
Install Vim-Plug
Simply run the following command to install Vim-Plug
, a plugin manager.
1
2
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
Init.vim
Open the Neovim
configuration file. This is typically located at ~/.config/nvim/init.vim
, create one if it doesn’t exist.
Inside init.vim
, add in the coc-nvim
plugin:
1
2
3
4
call plug#begin('~/.config/nvim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
Save and run :PlugInstall
to install the plugin. Then run :CocConfig
which changes coc-settings.json
, to make clangd
and rust-analyzer
work, we need to add the following:
1
2
3
4
{
"clangd.path": "/etc/profiles/per-user/yourusername/bin/clangd",
"rust-analyzer.server.path": "/etc/profiles/per-user/yourusername/bin/rust-analyzer"
}
I also usually add format file on save setting:
1
2
3
{
"coc.preferences.formatOnSaveFiletypes": ["*"]
}
Dotfiles
Check out my dotfiles.