diff --git a/modules/nvim.nix b/modules/nvim.nix index 398475e..ec45e5c 100644 --- a/modules/nvim.nix +++ b/modules/nvim.nix @@ -240,6 +240,12 @@ action = ":bp|bd #"; options = { desc = "Close current buffer"; }; } + { + mode = "n"; + key = "X"; + action = ":lua close_other_buffers()"; + options = { desc = "Close all buffers except current"; }; + } # System integration { @@ -317,6 +323,25 @@ } } + -- Close all buffers except current (preserving NvimTree and other special buffers) + function close_other_buffers() + local current_buf = vim.api.nvim_get_current_buf() + local buffers = vim.api.nvim_list_bufs() + + for _, buf in ipairs(buffers) do + if buf ~= current_buf and vim.api.nvim_buf_is_valid(buf) then + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local filetype = vim.api.nvim_buf_get_option(buf, 'filetype') + + -- Skip special buffers (NvimTree, terminals, quickfix, etc.) + if buftype == "" and filetype ~= "NvimTree" then + -- Only delete if it's a normal file buffer + vim.api.nvim_buf_delete(buf, { force = false }) + end + end + end + end + -- Unicode-safe file operations function open_file_with_system_app() local filepath = vim.fn.expand('%:p')