From 581aa42ccb048600abcb04d036850174a723d6d4 Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Sun, 21 Dec 2025 03:27:25 +0900 Subject: [PATCH] feat: allow lazy loading via vim.g.nvim_tree_config --- README.md | 5 +++++ lua/nvim-tree/api.lua | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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")