From bbb468c432a88afb1731b9bc1ce95b54aa661c1f Mon Sep 17 00:00:00 2001 From: Daniel Fainberg Date: Tue, 15 Sep 2026 13:27:06 +0200 Subject: [PATCH] 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 `Q`, prompting instead of failing on a modified buffer. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_015D4NsszUG7hy9ghKZ4nfhm --- modules/nvim.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/nvim.nix b/modules/nvim.nix index 9f3bfed..64e35da 100644 --- a/modules/nvim.nix +++ b/modules/nvim.nix @@ -285,7 +285,26 @@ in # Buffer navigation (no bufferline: cycle with Shift-h/l, list via fb) { mode = "n"; key = ""; action = "bnext"; options.desc = "Next buffer"; } { mode = "n"; key = ""; action = "bprevious"; options.desc = "Prev buffer"; } - { mode = "n"; key = "bd"; action = "bdelete"; 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 = "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 # hides it again. From inside the terminal, drops to normal mode and