From 27caccba18bc8bba457ebc2f959fe0df82e27038 Mon Sep 17 00:00:00 2001 From: kiyan Date: Fri, 3 Sep 2021 20:59:10 +0200 Subject: [PATCH] fix: switch buffers on close when closing the tree which is the last window, switches buffers instead of getting an input with a message to close nvim or ignore. --- lua/nvim-tree/view.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index b0dcee56..7a089e72 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -322,13 +322,17 @@ end function M.close() if not M.win_open() then return end if #a.nvim_list_wins() == 1 then - local ans = vim.fn.input( - '[NvimTree] this is the last open window, are you sure you want to quit nvim ? y/n: ' + local ok_bufs = vim.tbl_filter( + function(buf) + return a.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1 + end, + a.nvim_list_bufs() ) - if ans == 'y' then - vim.cmd "q!" + if #ok_bufs > 0 then + vim.cmd "sbnext" + else + vim.cmd "new" end - return end a.nvim_win_hide(M.get_winnr()) end