Neovim Python Plugin
Table of Contents
As I mentioned before, I had developed a vim plugin to write patients’ progress notes.
At that time, lazy.nvim was not that popular, so I used packer to manage the plugins.
Now that lazy.nvim is more popular and packer is not maintained, I decided to try lazy.vim.
The plugin uses pynvim to use python, and it was developed in the old style, which needs autoload/something.vim
, plugin/something.vim
and plugin python files python3/plugin-name/something.py
.
Now I am trying a new remote plugin style.
Pynvim document is somewhat explained poorly so I had to search a bit more about it. (References at the bottom)
Assuming dev environment is ready, here is the directory structure of a plugin.
Directory structure #
Top one for one with the directory, bottom one for simple one file plugin.
Directory must be in runtimepath
of neovim so that the plugin can be loaded. In lazy.nvim, below lua file is placed in ~/.config/nvim/lua/plugins
if managed in Structured Setup.
In my case, below lua file is placed in nvim-env-dir/.config/nvim-env-dir/lua/plugins
which is explained in another post.
return {
{ dir = "path/of/plugin/plugin-directory", dependencies = {} },
}
.
└── plugin-directory
└── rplugin
└── python3
└── name-of-the-plugin-module
├── __init__.py
└── main.py
.
└── plugin-directory
└── rplugin
└── python3
└── main.py
Module Directory structure #
# __init__.py
from .main import HelloPlugin
# main.py
import pynvim
@pynvim.plugin
class HelloPlugin(object):
def __init__(self, nvim):
self.nvim = nvim
@pynvim.command('HelloCommand', nargs='*', range='')
def hellocommand(self, args, range):
self.nvim.current.line = ('Hello with args: {}, range: {}'
.format(args, range))
Simple File structure #
# main.py
import pynvim
@pynvim.plugin
class HelloPlugin(object):
def __init__(self, nvim):
self.nvim = nvim
@pynvim.command('HelloCommand', nargs='*', range='')
def hellocommand(self, args, range):
self.nvim.current.line = ('Hello with args: {}, range: {}'
.format(args, range))