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