From 360f53ec4339ae6b2b743f97d1f6eac4bbc8f23c Mon Sep 17 00:00:00 2001 From: zymon Date: Tue, 27 Aug 2024 20:53:07 +0200 Subject: [PATCH] better buffer delestion --- lua/znvim/plugins/editor.lua | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lua/znvim/plugins/editor.lua b/lua/znvim/plugins/editor.lua index b28a1f9..e6c7483 100644 --- a/lua/znvim/plugins/editor.lua +++ b/lua/znvim/plugins/editor.lua @@ -1,6 +1,31 @@ return { - { -- file explorer + { -- use bdelete instead + "https://github.com/famiu/bufdelete.nvim", + config = function() + -- switches to Alpha dashboard when last buffer is closed + local alpha_on_empty = vim.api.nvim_create_augroup("alpha_on_empty", { clear = true }) + vim.api.nvim_create_autocmd("User", { + pattern = "BDeletePost*", + group = alpha_on_empty, + callback = function(event) + local fallback_name = vim.api.nvim_buf_get_name(event.buf) + local fallback_ft = vim.api.nvim_buf_get_option(event.buf, "filetype") + local fallback_on_empty = fallback_name == "" and fallback_ft == "" + if fallback_on_empty then + require("neo-tree").close_all() + vim.cmd("Alpha") + vim.cmd(event.buf .. "bwipeout") + end + end, + }) + end, + keys = { + { "bd", "Bdelete", desc = "delete buffer" }, + { "bD", "Bdelete!", desc = "delete buffer!" }, + }, + }, + { -- neo-tree file explorer "https://github.com/nvim-neo-tree/neo-tree.nvim", cmd = "Neotree",