fix(nvim): keep window layout when closing a buffer

`:bdelete` closes the window when no other listed buffer is left for it to
show, so closing the last file with neo-tree open left a full-width tree.
Point the window at another listed buffer, or a fresh empty one, before
deleting. `confirm` matches `<leader>Q`, prompting instead of failing on a
modified buffer.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015D4NsszUG7hy9ghKZ4nfhm
This commit is contained in:
2026-09-15 13:27:06 +02:00
co-authored by Claude Opus 5
parent 24b940810e
commit bbb468c432
+20 -1
View File
@@ -285,7 +285,26 @@ in
# Buffer navigation (no bufferline: cycle with Shift-h/l, list via <leader>fb) # Buffer navigation (no bufferline: cycle with Shift-h/l, list via <leader>fb)
{ mode = "n"; key = "<S-l>"; action = "<cmd>bnext<cr>"; options.desc = "Next buffer"; } { mode = "n"; key = "<S-l>"; action = "<cmd>bnext<cr>"; options.desc = "Next buffer"; }
{ mode = "n"; key = "<S-h>"; action = "<cmd>bprevious<cr>"; options.desc = "Prev buffer"; } { mode = "n"; key = "<S-h>"; action = "<cmd>bprevious<cr>"; options.desc = "Prev buffer"; }
{ mode = "n"; key = "<leader>bd"; action = "<cmd>bdelete<cr>"; options.desc = "Close buffer"; } # Plain `:bdelete` closes the window when no other listed buffer is left
# for it to show, which with neo-tree open leaves a full-width tree.
# Point the window at another buffer (or a fresh empty one) first, so the
# layout survives; `confirm` prompts rather than failing when modified.
{
mode = "n";
key = "<leader>bd";
action.__raw = ''
function()
local cur = vim.api.nvim_get_current_buf()
local listed = vim.tbl_filter(
function(b) return vim.bo[b].buflisted end,
vim.api.nvim_list_bufs()
)
if #listed > 1 then vim.cmd('bprevious') else vim.cmd('enew') end
vim.cmd('confirm bdelete ' .. cur)
end
'';
options.desc = "Close buffer";
}
# Terminal: toggle a horizontal or vertical split (toggleterm). Same key # Terminal: toggle a horizontal or vertical split (toggleterm). Same key
# hides it again. From inside the terminal, <C-w> drops to normal mode and # hides it again. From inside the terminal, <C-w> drops to normal mode and