vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 vim.opt.termguicolors = true local function handle_closed(window) local tab = vim.api.nvim_win_get_tabpage(window) local buffer = vim.api.nvim_win_get_buf(window) local info = vim.fn.getbufinfo(buffer)[1] local filter_window = function(w) return w ~= window end local windows = vim.tbl_filter(filter_window, vim.api.nvim_tabpage_list_wins(tab)) local buffers = vim.tbl_map(vim.api.nvim_win_get_buf, windows) if info.name:match('.*NvimTree_%d*$') then if not vim.tbl_isempty(buffers) then require('nvim-tree.api').tree.close() end return end if #buffers ~= 1 then return end local last_info = vim.fn.getbufinfo(buffers[1])[1] if last_info.name:match('.*NvimTree_%d*$') then vim.schedule(function() if #vim.api.nvim_list_wins() == 1 then vim.cmd 'quit' else vim.api.nvim_win_close(windows[1], true) end end) end end local config = function() require('nvim-tree').setup() vim.api.nvim_create_autocmd('WinClosed', { nested = true, callback = function() local window = tonumber(vim.fn.expand('')) vim.schedule_wrap(handle_closed(window)) end, }) end return { 'nvim-tree/nvim-tree.lua', config = config, keys = { { 'nt', ':NvimTreeToggle', desc = 'toggle nvim tree' } }, dependencies = { 'nvim-tree/nvim-web-devicons', opts = {} }, }