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.
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.
Now, when you change your config, you can use Telescope to reload it.