Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Using ~/.config/nvim/after/plugin For Neovim Mod Files

I'm experimenting with putting lua scripts to modify Neovim in:

Code

~/.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.

References

  • The subsection of the `runtimepath`` docs that talks about how the `after`` directories get loaded. Scoll up a bit to get a better idea of the entire process