Configuration Mechanism
Value of runtimepath option
The AstroNvim start-up code extends the value of runtimepath and it contains
not only $XDG_CONFIG_HOME/nvim but also $XDG_CONFIG_HOME/astronvim. Here,
$XDG_CONFIG_HOME is normally set to ~/.config.
This allows us to place user settings under the normal path of
~/.config/nvim/lua/user and the offset path of
~/.config/astronvim/lua/user.
Its value can be verified by :lua print(vim.go.runtimepath).
Shim function and its hook points
Configuration mechanism of AstroNvim uses the shim function
astronvim.user_opts (usually aliased to local variable
user_opts) when setting default values in the upstream source. The
resulting default values returned by this shim function are the user requested
combination of corresponding upstream and user settings.
Running rg user_opts at the root of the source tree should reveal many
hook points of user_opts calls in the source where the upstream sets
default values.
How AstroNvim works for user settings
Let us describe tersely in plain words how this shim function
astronvim.user_opts works in AstroNvim when it is called as
user_opts("MODULE", DEFAULT, EXTEND) with a twist of
oversimplification. This should provide some perspective for how AstroNvim
works for user settings.
- The
DEFAULTcontains a table setting the upstream default values. - The
"MODULE"contains a string specifying user settings by the module or variable name. - If the module named
user.MODULEexists, then AstroNvim obtains user settings from theuser.MODULEmodule.- This is the Splitting Up Configuration case.
- If the
EXTENDisnil(missing) ortrue, settings are extended:- If the
user.MODULEmodule returns a table, then AstroNvim assigns the returned table to theMODULEvariable, and generates settings by calling thevim.tbl_deep_extend("force", DEFAULT, MODULE)function extending theDEFAULTtable by theMODULEtable. - If the
user.MODULEmodule returns a function, then AstroNvim assigns the returned function to theMODULEvariable, and generates custom extended settings by calling theMODULEfunction with theDEFAULTas its argument.
- If the
- If the
EXTENDisfalse, settings are overridden:- If the
user.MODULEmodule returns a table, then AstroNvim ignoresDEFAULTand generates settings from theMODULEtable. - If the
user.MODULEmodule returns a function, then AstroNvim ignoresDEFAULTand generates settings by executing theMODULEfunction.
- If the
- If the module named
user.MODULEdoesn’t exist, then AstroNvim obtains user settings from theuser/init.luafile while looking for theMODULEvariable in it.- This is the single setting file case using the
user/init.luafile as discussed before. - If the
EXTENDisnil(missing) ortrue, settings are extended:- If the
MODULEvariable contains a table, then AstroNvim generates settings by calling thevim.tbl_deep_extend("force", DEFAULT, MODULE)function extending theDEFAULTtable by theMODULEtable. - If the
MODULEvariable contains a function, then AstroNvim generates custom extended settings by calling theMODULEfunction with theDEFAULTas its argument.
- If the
- If the
EXTENDisfalse, settings are overridden:- If the
MODULEvariable contains a table, then AstroNvim ignoresDEFAULTand generates settings from theMODULEtable. - If the
MODULEvariable contains a function, then AstroNvim ignoresDEFAULTand generates settings by executing theMODULEfunction.
- If the
- This is the single setting file case using the
- If neither the module named
user.MODULEnor the variable namedMODULEin theuser/init.luafile exist, then AstroNvim generates settings from the original upstreamDEFAULT.