Lua Config Directory Structure¶
Example Structure¶
~/.config/nvim
|-- after/
| |-- plugin/
|-- ftplugin/
|-- lua/
| |-- myluamodule.lua
| |-- other_modules/
| |-- anothermodule.lua
| |-- init.lua
|-- plugin/
|-- syntax/
|-- init.lua
~/.config/nvim/
¶
~/.config/nvim/lua
¶
The directory structure for lua files:
~/.config/nvim
|-- after/
|-- lua/
| |-- myluamodule.lua
| |-- other_modules/
| |-- anothermodule.lua
| |-- init.lua
|-- init.lua
Anything that goes in ~/.config/nvim/lua
can be loaded with require
Then the following Lua code will load myluamodule.lua
:
require("myluamodule")
.lua
extension.
Loading other modules in subdirectories (other_modules/anothermodule.lua
) is done with /
or .
:
require('other_modules/anothermodule')
-- or
require('other_modules.anothermodule')
Any directory that has an init.lua
file can be require
d directly, without
having to specify the name of the file:
require('other_modules') -- loads other_modules/init.lua
So, this structure:
~/.config/nvim
|-- after/
|-- ftplugin/
|-- lua/
| |-- myluamodule.lua
| |-- kolkhis/
| |-- set.lua
| |-- remap.lua
| |-- init.lua
|-- plugin/
|-- syntax/
|-- init.lua
~/.config/nvim/lua/kolkhis/init.lua
:
require('set')
require('remap')
You can require
it in ~/.config/nvim/init.lua
require('kolkhis') -- just the directory name, since there is an init.lua inside it
require
d in lua/kolkhis/init.lua
will be loaded.
~/.config/nvim/after/plugin/
¶
Anything in this directory will be automatically loaded after everything else.
Run Config Files from a Different Location¶
Set the $NVIM_APPNAME
variable to the location that you want nvim to look for
config files.
export NVIM_APPNAME='/home/kolkhis/test-nvim-config'
$XDG_CONFIG_HOME/nvim
, but will allow you to switch to a different configuration. Useful for testing.