-
I have a few plugin configs that are fairly large (e.g. LSP, cmp). For clarity I refactored some of the code into helper functions. However, this doesn't help readability as much if they're defined/nested inside the lazy -- init.lua
require("lazy").setup("plugins", { … })
-- lua/plugins/some-plugin.lua
{
…
config = function()
local verify = function(data) … end
if verify(foo) then … end
end
} Is is costly if functions are defined outside of -- lua/plugins/some-plugin.lua
local get_items = function() … end
local verify = function(data) … end
return {
"user/some-plugin.nvim",
event = { "BufNewFile", "BufReadPost" }, -- Lazy
config = function()
for _, e in ipairs(get_items()) do … end
if verify(foo) then … end
end
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can structure your config any way you like. Performance will be the same. You can also require external files in your config if needed. All files will be cached. |
Beta Was this translation helpful? Give feedback.
-
If you define your functions outside of config, you could potentially improve readability and organization of your code. And if you're worried about performance, you could always test it out and see if there's any noticeable difference in execution time. |
Beta Was this translation helpful? Give feedback.
You can structure your config any way you like. Performance will be the same. You can also require external files in your config if needed. All files will be cached.