Nvim-reload is a Neovim plugin that allows you to reload your entire Neovim config completely, including your start plugins. It also reloads all lua modules inside your Neovim config directory.
- Neovim >= 0.5
- plenary.nvim
use 'ashincoder/nvim-reload'
paq 'ashincoder/nvim-reload'
Plug 'ashincoder/nvim-reload'
Just install the plugin and it'll define a command for you, :Restart
, to reload and restart your Vim config, respectively. Note that 'restart' here just means reloading, it will not actually restart Vim.
You can also use the following Lua function require('nvim-reload').Restart()
instead of the :Restart
commands.
By default, nvim-reload reloads:
- Your init file.
- Your config files (VimL files in
stdpath('config')
. - Your start plugins (plugins that are automatically loaded when Neovim is started, located in
stdpath('data')/site/pack/*/start/*
).
NOTE: The asterisks used above are file globs, not literal asterisks.
In case you didn't know, Lua caches the modules you load using require()
. Which can prevent you from reloading your configuration since Lua will use the cached version of your config instead of the modified version. So the plugin also unloads the Lua modules inside your Neovim config located in stdpath('config')/lua
, which makes Lua actually reload them.
If you want, you can change the default behavior through the following configuration options.
-
vim_reload_dirs
- Table containing list of directories to reload the Vim files from. The plugin will look into the'compiler'
,'doc'
,'keymap'
,'syntax'
and'plugin'
subdirectories of each directory provided here and reload all VimL files in them.
Default:{ vim.fn.stdpath('config'), vim.fn.stdpath('data') .. '/site/pack/*/start/*' }
-
lua_reload_dirs
- Table containing list of directories to load the Lua modules from. The plugin will look into thelua
subdirectory of each directory provided here for modules to reload.
Default:{ vim.fn.stdpath('config') }
-
files_reload_external
- Table containing paths to external VimL files (files not inside any of thevim_reload_dirs
) to reload.
Default:{}
-
modules_reload_external
- Table containing Names of external modules (modules not inside any of thelua_reload_dirs
) to reload.
Default:{}
-
pre_reload_hook
- Function to run before reloading the config.
Default:nil
-
post_reload_hook
- Function to run after reloading the config.
Default:nil
local reload = require('nvim-reload')
-- If you use Neovim's built-in plugin system
-- Or a plugin manager that uses it (eg: packer.nvim)
local plugin_dirs = vim.fn.stdpath('data') .. '/site/pack/*/start/*'
-- If you use vim-plug
-- local plugin_dirs = vim.fn.stdpath('data') .. '/plugged/*'
reload.vim_reload_dirs = {
vim.fn.stdpath('config'),
plugin_dirs
}
reload.lua_reload_dirs = {
vim.fn.stdpath('config'),
-- Note: the line below may cause issues reloading your config
plugin_dirs
}
reload.files_reload_external = {
vim.fn.stdpath('config') .. '/myfile.vim'
}
reload.modules_reload_external = { 'packer' }
reload.post_reload_hook = function()
require('feline').reset_highlights()
end
NOTE: The directories provided in lua_reload_dirs
and vim_reload_dirs
can be globs, which will automatically be expanded by the plugin.
This plugin is still quite new and might have some bugs. And in case it does, feel free to make an issue and try to contribute PR's are welcome. Just fork it create a new branch and contribute.