diff --git a/nvim/.config/nvim/README.md b/nvim/.config/nvim/README.md index 38ec7cd..be72170 100644 --- a/nvim/.config/nvim/README.md +++ b/nvim/.config/nvim/README.md @@ -34,6 +34,8 @@ Buffer shortcuts: - `bp` previous buffer - `bn` next buffer - `bd` delete the current buffer +- `bc` force close all non-visible buffers +- `bf` find buffers Telescope shortcuts: diff --git a/nvim/.config/nvim/lua/romanzy/custom/buffers.lua b/nvim/.config/nvim/lua/romanzy/custom/buffers.lua new file mode 100644 index 0000000..cba1d78 --- /dev/null +++ b/nvim/.config/nvim/lua/romanzy/custom/buffers.lua @@ -0,0 +1,19 @@ +local M = {} + +function M.close_hidden() + local visible_buffers = {} + + for _, tabpage in ipairs(vim.api.nvim_list_tabpages()) do + for _, window in ipairs(vim.api.nvim_tabpage_list_wins(tabpage)) do + visible_buffers[vim.api.nvim_win_get_buf(window)] = true + end + end + + for _, buffer in ipairs(vim.api.nvim_list_bufs()) do + if vim.bo[buffer].buflisted and not visible_buffers[buffer] then + vim.api.nvim_buf_delete(buffer, { force = true }) + end + end +end + +return M diff --git a/nvim/.config/nvim/lua/romanzy/keymaps.lua b/nvim/.config/nvim/lua/romanzy/keymaps.lua index 3f417b1..8030e95 100644 --- a/nvim/.config/nvim/lua/romanzy/keymaps.lua +++ b/nvim/.config/nvim/lua/romanzy/keymaps.lua @@ -44,6 +44,8 @@ map("n", "re", "=", { desc = "equalize buffer sizes" }) map("n", "bp", "bprevious", { desc = "prev buffer" }) map("n", "bn", "bnext", { desc = "next buffer" }) map("n", "bd", "bdelete", { desc = "delete buffer" }) +map("n", "bc", require("romanzy.custom.buffers").close_hidden, { desc = "close hidden buffers" }) +map("n", "bf", telescope_picker("buffers"), { desc = "find buffers" }) map({ "n", "v" }, "y", '"+y', { desc = "yank to system clipboard" }) map("n", "Y", '"+Y', { desc = "yank line to system clipboard" })