Recently, I've decided to change my Neovim configuration to use Lua. If you want to do it too, this guide has much information about what you need to do.
In Lua, when you require a module, it is cached, so next time you require it, you are not getting the changes. The problem with this is that I usually have two open tabs with a few splits each when I'm working. After changing something in my config, I need to close Neovim to load everything again.
But, for my luck, a project named plenary.nvim exposes a function that can reload the Lua module. So I decided to create a Telescope picker to reload the module I changed.
After some research and copying a few snippets from TJ DeVries, I developed a solution that works pretty well.
The idea is to use Telescope to list my Lua modules, and when I click ctrl+e, it will call the Plenary function to reload the module. So this is how I did it.
I've namespaced my modules with ju, so my nvim folder looks like this:
βββ init.lua
βββ lua
βΒ Β βββ ju
βΒ Β βββ colors.lua
βΒ Β βββ compe.lua
βΒ Β βββ elixir.lua
βΒ Β βββ general.lua
βΒ Β βββ git.lua
βΒ Β βββ go.lua
βΒ Β βββ keymappings.lua
βΒ Β βββ lsp
βΒ Β βΒ Β βββ init.lua
βΒ Β βββ plugins.lua
βΒ Β βββ settings.lua
βΒ Β βββ telescope.lua
βΒ Β βββ treesitter
βΒ Β βΒ Β βββ init.lua
βΒ Β βββ utils
βΒ Β βββ init.lua
βΒ Β βββ reload.lua
in lua/ju/utils/reload.lua, I have two global helper functions. The first one just prints using the Neovim API, the second uses Plenary to reload the module and require it again.
P =
if pcall
In my Telescope config, I've created a new picker that will list just the files inside .config/nvim/lua, with a new keybinding to execute the above function.
I've added comments to the code, so it will be easier to follow.
local M =
return M;
I have this map that calls the function.
vim..
Now, when you change your config, you can use Telescope to reload it.