Capture outer scope variable in config function #513
-
Hello, I'm trying to capture a variable into a lambda function, but the variable is always nil. Minimal example: local my_var = 1
use({
"some-plugin",
config = function()
print("VAR: ", my_var) -- <-- prints nil
end
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Unfortunately, this is a well-known limitation of |
Beta Was this translation helpful? Give feedback.
Unfortunately, this is a well-known limitation of
string.dump
in Lua, which cannot capture closure variables. If you need this kind of capture, you can use a global, or you can pass a string instead of a function to theconfig
key (e.g.[[require(config.some-plugin)]]
, where~/.config/nvim/lua/config/some-plugin.lua
is a file that does whatever setup you want. Forthcoming changes in #402 will remove this limitation, as we will no longer need to usestring.dump
.