Use Vimscript and Python in your development workflow.
In my previous articles, I walked through with you how to develop a simple Neovim plugin using Neovim Lua APIs. For Python developers, there is a simpler solution as both Vim and Neovim support using Python for plugin development.
For Neovim (
:h provider-python), it supports Python
:h remote_plugin.txt) and the Vim legacy
python3 interfaces. To use Python plugins, you need the
pynvim module. Run
:checkhealth to see if you already have it.
For Vim (
:h python3), type
:version to check if Vim is built with Python 3 support.
Develop Plugins using Python
Let’s develop a few Vim/Neovim plugins using Python.
Text to Speech
With just a few lines of code, I can create a text-to-speech plugin.
- Install the
- Under your Vim/Neovim configuration folder, create a file called
:h autoload) folder.
- Add the following lines to
- Python code block is wrapped within the
python3keyword. To access Vim commands (
:h python-command), I use the
- Add the following key mappings.
nnoremap <Leader>es :call tts#Speak()<CR>
vnoremap <Leader>es :call tts#Speak(1)<CR>
<Leader>es and the current word under the cursor (
cWORD) will be converted to speech, or you can visually select a block of text.