Skip to content

Reliably determine if nvim-tree is last window and exit gracefully #1466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,25 @@ local function setup_autocommands(opts)
end,
})
end

if opts.quit_if_last_window then
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("NvimTreeClose", {clear = true}),
pattern = "NvimTree_*",
callback = function()
local layout = vim.api.nvim_call_function("winlayout", {})
if layout[1] == "leaf" and vim.api.nvim_buf_get_option(vim.api.nvim_win_get_buf(layout[2]), "filetype") == "NvimTree" and layout[3] == nil then vim.cmd("confirm quit") end
end
})
end



end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
auto_reload_on_write = true,
quit_if_last_window = false,
create_in_closed_folder = false,
disable_netrw = false,
hijack_cursor = false,
Expand Down