How to ensure packer.startup runs before require("package")? #651
-
I am installing a package (
packer.startup({
function(use)
...
use({
"lazytanuki/nvim-mapper",
config = function()
require("nvim-mapper").setup({})
end,
module = "nvim-mapper",
})
...
end
}) In another file, I want to
local mapper = require("nvim-mapper")
local map = function(mode, lhs, rhs, opts, category, unique_identifier, description)
mapper.map(mode, lhs, rhs, opts, category, unique_identifier, description)
end My main
...
require("plugins")
require("keybindings") However, even though I've
How can I ensure that the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is due to the order in which (Neo)vim sources files at startup.
There's a long-standing plan to move sourcing of the lazy-loaders to the very start of the startup process, but, until I have time to implement that large change, you have two options for workarounds:
I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the clarification! Prior to your above answer, I found the section in your docs about the Below is the code:
It seems to work, although is perhaps not optimal... not sure? Any comments on my so called "solution"? Thanks again! |
Beta Was this translation helpful? Give feedback.
This is due to the order in which (Neo)vim sources files at startup.
packer
, by default, outputs its loader code toplugin/packer_compiled.lua
. This code includes the setup necessary for themodule
lazy-loader to work. The files inplugin/
are all automatically sourced during startup, but after yourinit.lua
runs - so, yourrequire
fails.There's a long-standing plan to move sourcing of the lazy-loaders to the very start of the startup process, but, until I have time to implement that large change, you have two options for workarounds:
require('keybindings')
in a file that runs afterplugin/packer_compiled.lua
, e.g.plugin/x_keybindings.lua
or similar (ordering is lexicographic).