Setting up Neovim plus Coc for Python, C++, Go, Rust and javascript

There is no doubt, coding is getting more complex nowadays. I have to code in Python, C and C++ and I have usually used vi for small edits. For production I have used PyCharm, for C, C++ Visual Studio.

Visual Studio Code is a great editor with multiple extensions to support different languages. Although, I am used to vim and I always tried to setup intellisense to support different languages.

I like to use Visual Studio Code, however, I feel more productive with vi editor. In this post I’m setting up NeoVim with Coc to code in my favorite languages. In the past I tried vim with different plugins to have code completion.

Finally, I think NeoVim plus Coc is a good option to use vim.

COC requires nodejs and yarn. So, first step is to install those tools:

Install nodejs, create node repo:

curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash 

Install nodejs

sudo dnf install nodejs

Install yarn:

Create yarn repo with

[yarn]
name=Yarn Repository
baseurl=https://dl.yarnpkg.com/rpm/
enabled=1
gpgcheck=1
gpgkey=https://dl.yarnpkg.com/rpm/pubkey.gpg

Install yarn

sudo dnf install yarn

Install Vim Plug:

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'

Setup Plugin Manager in your init.vim file:

Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}

Launch NeoVim and manage code completion from inside NeoVim. This is what I like more about COC, you can install all the code completion extensions using CocInstall:

Neovim. Show Installed Coc Extensions
CocInstall coc-rust-analyzer and others....
CocInstall Output

PYTHON

Notes: Set interpreter to python 3. Optional use Jedi or language server. I’ll use Jedi:

I had to remove python3-jedi package from Fedora and install it with pip3. You can use CocConfig to setup json file and toggle jedi or language server.

Code Completion JEDI
Code Completion JEDI disabled

C++

Code completion using clangd

RUST

You need to setup Rust-Analyzer with CocConfig

GO

Code completion using gopls

SetUp Go settings with CocConfig.

My coc-settings.json:


From CocConfig

Add a network bridge to your KVM/qemu Virtual Machines.

I was used to SetUp VirtualBox Guests with a Network Bridge in order to have bidirectional access from Host to Guest or Guest to Host. In the simpler NAT mode, I was only able to ssh from my Host to Guest but not ssh from Guest to Host.

Most of the time I used the Bridge Network Mode in Virtual Box, then I switched from Virtual Box to KVM/qemu/libvirtd. Thanks to virt-manager or Gnome Boxes it was relatively easy to use those tools instead of VirtualBox.

When using virt-manager, you have the option to setup the network mode from GUI. Unfortunately there is not an option in drop box to select Network bridge. Instead we have to create the bridge from command line.

Use Network Manager Client to create “br0” bridge interface, in my case the physical Ethernet network interface (From a ThinkPad docking) is: enp0s20f0u2u1i5.

 sudo nmcli con add ifname br0 type bridge con-name br0                                                                                  
sudo nmcli con add type bridge-slave ifname enp0s20f0u2u1i5 master br0                                                                  

Bring down physical Ethernet interface and bring up bridge br0.

sudo nmcli con down "Wired connection 1"                                                                                                 
sudo nmcli connection up br0

Setup xml file to be used by virsh:

Use virsh:

sudo virsh net-define ./kvm_br0.xml                                                                                                      
sudo virsh net-start br0                                                                                                      
sudo virsh net-autostart br0                                                                                                             

You will see bridge br0 in drop box from virt-manager

My host now has IP Address 192.168.0.104

My KVM guess has IP Address 192.168.0.105. Then, thanks to bridge I can ssh from Ubuntu Guest to my Fedora Host!

You can modify bridge IP address manually as well. For instance, use:

nmcli connection modify br0 ipv4.addresses '192.168.X.X/24'
nmcli connection modify br0 ipv4.gateway '192.168.X.254'
nmcli connection modify br0 ipv4.dns '192.168.X.254'
nmcli connection modify br0 ipv4.method manual