Neovim plugin for easier plugin development in lua.
Allows you to:
- reload your plugin during the development and test it in the current instance of neovim
- run lua statement(s)
- evaluate expression and see the result or error and what was printed while running in floating window
This plugin was written with usage of new features of Neovim 0.7.
Example configuration with packer.nvim
:
use({
'synaptiko/evalua.nvim',
config = function()
local evalua = require('evalua')
local augroup = vim.api.nvim_create_augroup('evalua_mappings', { clear = true })
vim.api.nvim_create_autocmd('FileType', {
group = augroup,
pattern = 'lua',
callback = function()
vim.keymap.set('n', '<Leader>r', evalua.run, { buffer = true, silent = true })
vim.keymap.set('n', '<Leader>e', evalua.eval, { buffer = true, silent = true })
vim.keymap.set('v', '<Leader>r', evalua.run_block, { buffer = true, silent = true })
vim.keymap.set('v', '<Leader>e', evalua.eval_block, { buffer = true, silent = true })
end,
})
vim.api.nvim_create_user_command('EvaluaEnableReload', function()
vim.keymap.set('n', '<Leader>a', evalua.reload, { silent = true })
end, {})
end,
requires = 'nvim-lua/plenary.nvim'
})
then sync your plugins:
:PackerSync
Now you should be ready to use the plugin in your plugins or lua files.
Before you can develop your plugin, make sure to start your neovim instance with runtimepath
which contains .
(current working directory, which should be root of your plugin). Here's an example alias:
alias vp="vim +\"let &rtp='.,'.&rtp\""
To use plugin reload feature in your plugin, you need to create development-reload.lua
files in the root of your plugin. Here's example of evalua
's one:
require('evalua').unload('evalua')
local evalua = require('evalua')
vim.keymap.set('n', '<Leader>r', evalua.run, { silent = true })
vim.keymap.set('n', '<Leader>e', evalua.eval, { silent = true })
vim.keymap.set('v', '<Leader>r', evalua.run_block, { silent = true })
vim.keymap.set('v', '<Leader>e', evalua.eval_block, { silent = true })
vim.keymap.set('n', '<Leader>a', evalua.reload, { silent = true })
The important part is require('evalua').unload('<your-plugin-name>')
. After that you can require your plugin again, it will load an up-to-date version of it. The unload
function will take care of nested imports like my-plugin.utils
or my-plugin/utils
.
Feel free to provide any type of "testing" code you need to run after your plugin is reloaded during development, ie. bind some keymaps.
Another use-case is when you need to verify that specific part of your plugin works as expected. You can use run
, eval
and run_block
and eval_block
functions for that. The run
function only runs the statements and won't show anything while eval
will show you a floating window with results. You can close this window by pressing <Esc>
, or you can copy some part of it for later.