CMake Neovim Python Plugin
As part of the changes included in Neovim there is a new plugin model where plugins are separate processes which Neovim communicates to using the MessagePack protocol.
Since plugins are distinct from the Neovim process, it is possible to write plugins in many languages.
This is a minimal example of a Python plugin. When you want to create a new Python plugin, you should be able to (and feel free to) copy this repository, rename a couple files, include the plugin in your Vim config and see something happen.
The intention of this repository is to make it quick and easy to start a new plugin. It is just enough to show how to make the basics work.
git clone --depth 1 https://github.com/jacobsimpson/nvim-example-python-plugin ~/.vim/bundle/nvim-example-python-plugin rm -Rf ~/.vim/bundle/nvim-example-python-plugin/.git
I use NeoBundle so this is an example of how to load this plugin in NeoBundle.
" Required: call neobundle#begin(expand('~/.vim/bundle/')) " Let NeoBundle manage NeoBundle " Required: NeoBundleFetch 'Shougo/neobundle.vim' " You probably have a number of other plugins listed here. " Add this line to make your new plugin load, assuming you haven't renamed it. NeoBundle 'nvim-example-python-plugin' call neobundle#end()
If you use vim-plug, you can add this line to your plugin section:
:PlugInstall, the files should appear in your
~/.config/nvim/plugged directory (or whatever path you have configured for plugins).
This plugin code works with Python 2. You can make it work with Python 3 by changing the
rplugin/python directory to be
rplugin/python3. See the python-client remote plugin documentation for more information.
The next thing to do is to initialize the manifest for the Python part of the plugin. The manifest is a cache that Vim keeps of the interface implemented by the Python part of the plugin. The functions and commands it implements.
To initialize the manifest, execute:
NOTE: After initializing the manifest, you must restart neovim for the python functions be be available.
There is some VimL in the plugin that will print when Neovim is starting up:
Starting the example Python Plugin
That will confirm that the VimL portions of the plugin are loading correctly.
There is a function defined in the VimL portion of the plugin which echos some text. You can execute the function like this:
Now that the manifest is initialized, it should be possible to invoke the function defined in the Python part of the plugin. Look in __init__ to see the implementation.
On it's own, this plugin doesn't do anything interesting, so the expectation is that you will want to modify it.
Run the unit tests:
python3 -m unittest -v tests/rplugin/python3/test_cmake.py