You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB
Lua

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 function filter_window(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 function config()
require('nvim-tree').setup()
vim.api.nvim_create_autocmd('WinClosed', {
nested = true,
callback = function()
local window = tonumber(vim.fn.expand('<amatch>'))
handle_closed(window)
end,
})
end
return {
'nvim-tree/nvim-tree.lua',
config = config,
keys = {
{ '<leader>nt', ':NvimTreeToggle<CR>', desc = 'toggle nvim tree' }
},
dependencies = {
'nvim-tree/nvim-web-devicons', opts = {}
},
}