I am going to write my nvim config in lua. I want to use this config on several computers. And vim configuration on these computers should be slightly different. For example, on some installations I want plugin X to be installed, but on others - not.

So I want to create some installation-specific file in ~/.config/nvim. Kind of config file for my vim config. (and no, I will not go deeper). As this file is different on different installations I will not commit it, but rest of lua configuration scripts will read it and act accordingly.

What format is most appropriate for this file? For example, if I make it yaml, will it be possible to open and parse it from init.lua ?

2 Answers 2


Instead of using a separate YAML file, one option is to just use Lua directly. Use simple Lua syntax to populate a Lua table from your local config file.

Perhaps something like:

localconfig = {}
dofile(os.getenv("HOME") .. "/.config/nvim/localconfig.lua")

And then in file ~/.config/nvim/localconfig.lua you can add:

localconfig.setting1 = "value1"
localconfig.setting2 = 2
localconfig.setting3 = {4, 9, 16}


You can initialize localconfig in your init.lua with defaults before you load the overrides.


You can use lua-yaml to parse Yaml files from Lua.

Or use the Lua binding to LibYAML lyaml

  • 1
    But to use these packages I need to install them first. How do I install any of these packages in such a way that lua interpreter built into nvim would be able to use them? If I simply white require('yaml') in my lua.init I just get an error: module 'yaml' not found
    – lesnik
    Commented Feb 10, 2023 at 15:35
  • I suppose you can catch the exception raise by requires and launch the LuaRocks command: LuaRocks install lua-yaml Commented Feb 10, 2023 at 15:47
  • 1
    I guess LuaRocks would install package for system lua. I highly doubt that the lua interpreter built into vim would be able to use it. Anyway, I do not have LuaRocks installed, and lua could be not installed on the system at all.
    – lesnik
    Commented Feb 10, 2023 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.