First of all, I’ve been using vim exclusively since my The Road to Mastering Vim blog post! Actually I’m not using vim at all. I decided to use neovim, which is literally the future of vim, instead. I’ve also decided to donate a monthly sum to their Bountysource.
anyway, neovim has a python client that implements support for python plugins in neovim. It also serves as a library for connecting to and scripting neovim processes through its msgpack-rpc API.
That poses an issue: pip doesn’t have an auto update mechanism. So how do I update the client packages every time neovim is updated, automatically?
The solution
This is a three step solution. We’ll be hooking into dpkg install process and run a script that updates neovim client libraries when neovim is being installed / updated.
Create a dedicated virtualenv for neovim
First, install and configure: virtualenv, virtualenvwrapper.
Then, create python2 and python3 virtualenvs for neovim:
- Run:
mkvirtualenv -p python2 neovim2
- Run:Â
pip install neovim
- Repeat step 1-2 for python 3
Now, edit your vimrc file and add the following:
let g:python_host_prog = $WORKON_HOME."/neovim2/bin/python" |
Create a script that updates the client library
The following script updates all the packages inside neovims virtualenvs.
You’ll probably need to change it a little bit to suite your needs:
- It uses zsh, you might be using bash.
- It configures virtualenvwrapper to
$HOME/.virtualenvs
, yours might be different. - It configures virtualenvwrapper python to
/usr/bin/python3
, yours might be different.
|
Configure dpkg to call the script
dpkg has a neat feature that allows hooking scripts into various dpkg actions. The Pre-Install-Pkgs
hook is exactly what we need.
This hook runs after a set of packages has been downloaded, and before they are installed. The list of packages is passed to standard input (stdin).
First, copy the update script to a directory of your choosing (We’ll be using /opt/nvim
), then configure dpkg:
sudo bash -c "echo 'DPkg::Pre-Install-Pkgs {\"/opt/nvim/update-nvim.zsh\";};' > /etc/apt/apt.conf.d/99update-nvim" |
and we’re done!
$ sudo apt install neovim |