The runtimepath
When Neovim starts up, init.lua
isn’t the only configuration file that Neovim looks for. Neovim actually looks for a bunch of additional configuration files on something called the runtimepath.
What is the runtimepath?
The runtimepath is a group of directories that Neovim will search inside of when it starts up for these additional configuration files. They can be directories internal to Neovim, but can also be created by the user too.
Opening Neovim and running :h runtimepath
will give you an exhaustive list of these directories.
You can see that it searches a lot of different directories including as the very first one $XDG_CONFIG_HOME/nvim
- our config directory!
Underneath this, it then lists all of the directories it will look for when Neovim runs, from within the first list of directories.
So for example, it will search $XDG_CONFIG_HOME/nvim
and some other internal directories for a colors/
directory, plugin/
directory, lua/
directory, etc.
Testing the runtime path directories
Create the directory .config/nvim/plugin/
. Inside of it, create a hello.lua
file. Open it and write print(“Hello from plugin!”), save the file, and re-load or source Neovim. As it’s on the runtimepath, It will run the code every time you open Neovim - just like the init.lua file.