Quick setup for Neovim and C++
22 Jul 2020For some reason, setting up Neovim and adding C++ support took me ages, so I decided to write it down.
Install Neovim and setup a package manager. Neovim tells you how. Instructions for installation are also all over the internet
In the neovim folder I create a virtual environment. This way I can more easily track what packages neovim needs and is using and avoid adding packages globally. (You can also do the same for python2).
python3 -m venv neovim3
source neovim3/bin/activate
pip install pynvim
Then add tell neovim about this virtualenv by adding this line to the init.vim
let g:python3_host_prog='/home/{YOUR_USER}/.config/nvim/neovim3/bin/python'
Now for C++ support and autocompletion. I decided to use deoplete because I liked the authors arguments for making it and had read a few people describe more standard alternatives as a over the top, un-vim-like even. I decided I wanted to be a purist too; despite knowing nothing about any of it. Also I like the authors writing style.
I found this jdhao post the most detailed on deoplete, C++ and Neovim. But didn’t use much of the same steps they did.
Perhaps I will later discover that building from source is necessary for something, but for now I have no idea why you’d prefer that. See this SO question. Instead, a simple way:
sudo apt install llvm
sudo apt install clang
With the background done, add deoplete
and deoplete-clangx to your plugins
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/deoplete-clangx'
(There is also a plugin, deoplete-clang, but that appears older and less well maintained).
Now close nvim, reopen, and run :PlugInstall
, then :checkhealth
. (I forgot :PlugInstall after adding deoplete-clangx and spent many hours “debugging”, this was part of the reason I decided to write these steps down…).
At this point when I open a C++ file I see the clangx autocomplete suggestions from deoplete.