Reload your neovim config on the fly! It works with any lua file.
- The main case of use is to re-apply your Neovim config without having to close and re-open Neovim.
- But you can use it to load any lua file.
Make sure the files you specify on reload_files
are actually suitable to be hot-reloaded.
- Example: If you hot-reload a file that create autocmds, be aware hot-reloading the file won't delete any previously loaded autocmd. Same thing for highlights, variables, etc.
In the example we use the lazy package manager
{
"Zeioth/hot-reload.nvim",
dependencies = "nvim-lua/plenary.nvim",
event = "BufEnter",
opts = {}
}
All options described here are 100% optional and you don't need to define them to use this plugin.
Name | Default value | Description |
---|---|---|
reload_files | string[] |
Table of file paths with the files you want to hot-reload. |
reload_callback | function() end |
Optional function where you can specify things to do after the files have hot-reloaded. See example below. |
reload_all | true |
If true, all files in reload_files will hot-reload every time you write any of the files included in reload_files , in order. If false, only the file you write will be reloaded. |
notify | true |
If true, a notification will be displayed when a file is hot-reloaded. |
event | BufWritePost |
Event that trigger the hot-reload. Don't change this unless you know what you are doing. |
-- hot-reload.nvim [config reload]
-- https://github.com/Zeioth/hot-reload.nvim
{
"Zeioth/hot-reload.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
event = "BufEnter",
opts = function()
local config_dir = vim.fn.stdpath("config") .. "/lua/base/"
return {
-- Files to be hot-reloaded when modified.
reload_files = {
config_dir .. "1-options.lua",
config_dir .. "4-mappings.lua"
},
-- Things to do after hot-reload trigger.
reload_callback = function()
vim.cmd(":silent! colorscheme " .. vim.g.default_colorscheme) -- nvim colorscheme reload command.
vim.cmd(":silent! doautocmd ColorScheme") -- heirline colorscheme reload event.
end
}
end
},
One of the biggest challenges NormalNvim face is marketing. So share the project and tell your friends!
This GPL3 Neovim plugin has been developed for NormalNvim. It's based on the GPL3 hot reload snippet from AstroNvim v3. So please support both projects if you enjoy this plugin.
- Can I use this on any Neovim distro?
Yes
. It is distro agnostic, as all the plugins released by NormalNvim. - Can I use this plugin to reload my plugins too?
Lazy
will reload the plugins automatically when you modify their config. But if you are using any other plugin manager, you might want to.
- It would be a cool idea to allow specifying a callback per file to hot-reload. But it's unclear how many people would actually use this.
- It would be cool (but not necessary) to have an option
reload_directories
.