From c3d8dc3e1d23f74f02f7972d9d40bfe3dddd394f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 17 Aug 2024 17:32:24 +0200 Subject: [PATCH] Add mapping to delete other buffers --- lua/mappings.lua | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index f297695..7b4980e 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -45,7 +45,21 @@ keymap.set("n", [[\x]], "windo lclose cclose ", { -- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933 keymap.set("n", [[\d]], "bprevious bdelete #", { silent = true, - desc = "delete buffer", + desc = "delete current buffer", +}) + +keymap.set("n", [[\D]], function() + local buf_ids = vim.api.nvim_list_bufs() + local cur_buf = vim.api.nvim_win_get_buf(0) + + for _, buf_id in pairs(buf_ids) do + -- do not Delete unlisted buffers, which may lead to unexpected errors + if vim.api.nvim_get_option_value("buflisted", { buf = buf_id }) and buf_id ~= cur_buf then + vim.api.nvim_buf_delete(buf_id, { force = true }) + end + end +end, { + desc = "delete other buffers", }) -- Insert a blank line below or above current line (do not move the cursor), @@ -218,18 +232,20 @@ keymap.set("n", "cb", function() return end - timer:start(0, 100, vim.schedule_wrap(function() - vim.cmd [[ + timer:start( + 0, + 100, + vim.schedule_wrap(function() + vim.cmd([[ set cursorcolumn! set cursorline! - ]] + ]]) - if cnt == blink_times then - timer:close() - end + if cnt == blink_times then + timer:close() + end - cnt = cnt + 1 - end) + cnt = cnt + 1 + end) ) -end, - { desc = "show cursor" }) +end, { desc = "show cursor" })