diff --git a/README.md b/README.md index 057ebf9db96..fbb308655e1 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,11 @@ require("nvim-tree").setup({ dotfiles = true, }, }) + +-- OR use the following variable and nvim-tree will call setup lazily +vim.g.NvimTreeConfig = { + on_attach = my_on_attach +} ``` ### Help diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index e5a109142f1..ea50eeb79a2 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -50,7 +50,11 @@ local Api = { ---@return fun(...): any local function wrap(fn) return function(...) - if vim.g.NvimTreeSetup == 1 then + if vim.g.NvimTreeSetup == 1 or vim.g.NvimTreeConfig then + if vim.g.NvimTreeSetup ~= 1 then + require("nvim-tree").setup(vim.g.NvimTreeConfig) + end + return fn(...) else notify.error("nvim-tree setup not called")