[Feature Request]: Add `BufferLineCloseHidden` method
fioncat opened this issue · comments
wenqian commented
What?
Provide a BufferLineCloseHidden
method to close hidden buffers while preserving open windows.
Here is a simple implement:
local delete_hiddent_buffer = function()
local non_hidden_buffer = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
local buf = vim.api.nvim_win_get_buf(win)
non_hidden_buffer[buf] = true
end
local buffers = vim.api.nvim_list_bufs()
for _, buf in ipairs(buffers) do
local modified = vim.fn.getbufvar(buf, "&modified")
-- we won't delete modified buffer
if modified ~= 1 and non_hidden_buffer[buf] == nil then
vim.api.nvim_buf_delete(buf, {
force = false,
})
end
end
require("bufferline.ui").refresh()
end
Why?
Currently, there is BufferLineCloseOthers
, but it closes other open windows. In split-screen scenarios, I often wish to keep the open windows while closing other buffers.
Akin commented
@fioncat there are many plugins such as nvim-bufdelete
and numerous others that solve the problem of closing X buffer and not messing with the window arrangement. I'm not going to add that natively here because there are already good enough solutions and frankly I'm not looking to maintain even more functionality (which will just bring all it's own issues)