From dcfd134a4e8e722364ba8eb68cb10b5c7066ac42 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sat, 4 Oct 2025 12:50:47 +0800 Subject: [PATCH] feat(nvim): close nvim-tree when its the only window left --- .../editor/neovim/nvim/lua/plugins/nvim-tree.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/coding/editor/neovim/nvim/lua/plugins/nvim-tree.lua b/modules/coding/editor/neovim/nvim/lua/plugins/nvim-tree.lua index 36f2fc5..3e95c90 100644 --- a/modules/coding/editor/neovim/nvim/lua/plugins/nvim-tree.lua +++ b/modules/coding/editor/neovim/nvim/lua/plugins/nvim-tree.lua @@ -17,4 +17,16 @@ local opt = require("core.globals").keymap_opt vim.keymap.set("n", "e", ":NvimTreeToggle", opt) vim.keymap.set("n", "te", ":NvimTreeFocus", opt) -return M +vim.api.nvim_create_autocmd("BufEnter", { + group = vim.api.nvim_create_augroup("NvimTreeCloseOnLast", { clear = true }), + pattern = "NvimTree*", + callback = function() + if vim.api.nvim_call_function("winlayout", {})[1] == "leaf" and vim.bo.filetype == "NvimTree" then + vim.defer_fn(function() + vim.cmd("NvimTreeClose") + end, 10) + end + end, +}) + +return M \ No newline at end of file