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
DEFAULT
contains 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.MODULE
exists, then AstroNvim obtains user settings from theuser.MODULE
module.- This is the Splitting Up Configuration case.
- If the
EXTEND
isnil
(missing) ortrue
, settings are extended:- If the
user.MODULE
module returns a table, then AstroNvim assigns the returned table to theMODULE
variable, and generates settings by calling thevim.tbl_deep_extend("force", DEFAULT, MODULE)
function extending theDEFAULT
table by theMODULE
table. - If the
user.MODULE
module returns a function, then AstroNvim assigns the returned function to theMODULE
variable, and generates custom extended settings by calling theMODULE
function with theDEFAULT
as its argument.
- If the
- If the
EXTEND
isfalse
, settings are overridden:- If the
user.MODULE
module returns a table, then AstroNvim ignoresDEFAULT
and generates settings from theMODULE
table. - If the
user.MODULE
module returns a function, then AstroNvim ignoresDEFAULT
and generates settings by executing theMODULE
function.
- If the
- If the module named
user.MODULE
doesn’t exist, then AstroNvim obtains user settings from theuser/init.lua
file while looking for theMODULE
variable in it.- This is the single setting file case using the
user/init.lua
file as discussed before. - If the
EXTEND
isnil
(missing) ortrue
, settings are extended:- If the
MODULE
variable contains a table, then AstroNvim generates settings by calling thevim.tbl_deep_extend("force", DEFAULT, MODULE)
function extending theDEFAULT
table by theMODULE
table. - If the
MODULE
variable contains a function, then AstroNvim generates custom extended settings by calling theMODULE
function with theDEFAULT
as its argument.
- If the
- If the
EXTEND
isfalse
, settings are overridden:- If the
MODULE
variable contains a table, then AstroNvim ignoresDEFAULT
and generates settings from theMODULE
table. - If the
MODULE
variable contains a function, then AstroNvim ignoresDEFAULT
and generates settings by executing theMODULE
function.
- If the
- This is the single setting file case using the
- If neither the module named
user.MODULE
nor the variable namedMODULE
in theuser/init.lua
file exist, then AstroNvim generates settings from the original upstreamDEFAULT
.