From e2e3bc2df4490690ea005395eecdc8eeb30c4def Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sun, 24 Dec 2023 02:00:57 +0000 Subject: [PATCH] fix: Neovim closes on bdelete (#333) --- lua/aerial/autocommands.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/aerial/autocommands.lua b/lua/aerial/autocommands.lua index 554197a..fb64419 100644 --- a/lua/aerial/autocommands.lua +++ b/lua/aerial/autocommands.lua @@ -95,7 +95,15 @@ M.on_enter_buffer = util.throttle(function() (not source_win and config.attach_mode ~= "global") or vim.tbl_count(vim.api.nvim_tabpage_list_wins(0)) == 1 then - vim.cmd("quit") + -- If aerial is the last window open, we must have closed the other windows. If the others + -- were closed via "quit" or similar, we should quit neovim. + local last_cmd = vim.fn.histget("cmd", -1) + local cmd1 = last_cmd:sub(1, 1) + local cmd2 = last_cmd:sub(1, 2) + local cmd3 = last_cmd:sub(1, 3) + if cmd2 == "wq" or cmd1 == "q" or cmd1 == "x" or cmd3 == "exi" then + vim.cmd.quit() + end end return end