Using ~/.config/nvim/after/plugin For Neovim Mod Files
I'm experimenting with putting lua scripts to modify Neovim in:
~/.config/nvim/after/plugin
Any .lua
files in that directory get loaded as one of the last parts of pulling things into the runtime. So, pretty much everything else should be loaded.
My thinking is to make it easier to break out parts of my config into the individual files and to make it easier to add little scripts to mod behavior.
For example, putting this script in the directory configures Neovim to print "File saved!" every time a file is written
~/.config/nvim/after/plugin/example.lua
vim.api.nvim_create_autocmd("BufWritePost", {
group = vim.api.nvim_create_augroup("EaxmpleFileSaveMessage", { clear = true }),
callback = function()
print("File saved!")
end,
})
That's not particullarly useful, but it proves the point that autocmds can be setup from the directory.
Postscript
So far. So good. I've created a half dozen files and everything is working as expected.
References
-
The subsection of the
runtimepath
docs that talks about how theafter
directories get loaded. Scoll up a bit to get a better idea of the entire process