From 1dcec87c89b3585d74924263de654fcc872e39af Mon Sep 17 00:00:00 2001 From: Pradyuman Vig Date: Tue, 8 Sep 2026 00:05:29 -0400 Subject: [PATCH] fix: close side buffers when splitting current buffer --- lua/zen/init.lua | 4 ++-- tests/test_splits.lua | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lua/zen/init.lua b/lua/zen/init.lua index 2789ba3..62054b0 100644 --- a/lua/zen/init.lua +++ b/lua/zen/init.lua @@ -559,7 +559,7 @@ local function setup(options) desc = "Recreate the side buffers if they are closed.", }) - vim.api.nvim_create_autocmd({ "BufWinEnter", "FileType" }, { + vim.api.nvim_create_autocmd({ "BufWinEnter", "FileType", "WinNew" }, { pattern = "*", callback = function(args) if is_popup_window(vim.api.nvim_get_current_win()) then @@ -567,7 +567,7 @@ local function setup(options) end local filetype = vim.bo[args.buf].filetype local is_integration = is_buff_integration(args.buf) - if args.event == "BufWinEnter" then + if args.event == "BufWinEnter" or args.event == "WinNew" then if filetype ~= "" and not is_integration and vim.tbl_count(get_vsplits()) >= 2 then close_side_buffer("left") close_side_buffer("right") diff --git a/tests/test_splits.lua b/tests/test_splits.lua index 35e680f..1dc5e57 100644 --- a/tests/test_splits.lua +++ b/tests/test_splits.lua @@ -25,6 +25,19 @@ T["vsplit"]["opening closes zen side buffers"] = function() }) end +T["vsplit"]["splitting the current buffer closes zen side buffers"] = function() + child.cmd("edit test.lua") + child.cmd("vsplit") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "lua", buftype = "", width = 120, height = 50 }, + { type = "leaf", filetype = "lua", buftype = "", width = 119, height = 50 }, + }, + }) +end + T["vsplit"]["closing reopens zen side buffers"] = function() child.cmd("edit test.lua") child.cmd("vsplit test2.lua")