feat(util): mini.bufremove
is no longer needed
This commit is contained in:
7
NEWS.md
7
NEWS.md
@ -2,6 +2,12 @@
|
||||
|
||||
## 11.x
|
||||
|
||||
- new option `vim.g.deprecation_warnings` to disable deprecation warnings
|
||||
Defaults to `false`. To disable, set it to `true` in your `options.lua`
|
||||
|
||||
- `vim-illuminate` move to extras
|
||||
Document highlights now use native lsp functionality by default
|
||||
|
||||
Since Neovim 0.10 has been released, I've been working on a new version of **LazyVim**
|
||||
that is fully compatible with all the latest Neovim features.
|
||||
|
||||
@ -32,7 +38,6 @@ Additionally, some core plugins have been moved to extras.
|
||||
- `mini.surround`
|
||||
- `mini.indentscope` scopes are now also highlighted with `indent-blankline`
|
||||
- `nvim-treesitter-context`
|
||||
- `vim-illuminate`: document highlights now use native lsp functionality by default
|
||||
|
||||
- There's a new extra for the `nvim-treesitter` **rewrite**.
|
||||
Since the rewrite is not backward compatible, some plugins will be disabled
|
||||
|
@ -37,6 +37,8 @@ map("n", "[b", "<cmd>bprevious<cr>", { desc = "Prev Buffer" })
|
||||
map("n", "]b", "<cmd>bnext<cr>", { desc = "Next Buffer" })
|
||||
map("n", "<leader>bb", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
|
||||
map("n", "<leader>`", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
|
||||
map("n", "<leader>bd", LazyVim.ui.bufremove, { desc = "Delete Buffer" })
|
||||
map("n", "<leader>bD", "<cmd>:bd<cr>", { desc = "Delete Buffer and Window" })
|
||||
|
||||
-- Clear search with <esc>
|
||||
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and Clear hlsearch" })
|
||||
|
@ -409,33 +409,6 @@ return {
|
||||
},
|
||||
},
|
||||
|
||||
-- buffer remove
|
||||
{
|
||||
"echasnovski/mini.bufremove",
|
||||
keys = {
|
||||
{
|
||||
"<leader>bd",
|
||||
function()
|
||||
local bd = require("mini.bufremove").delete
|
||||
if vim.bo.modified then
|
||||
local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel")
|
||||
if choice == 1 then -- Yes
|
||||
vim.cmd.write()
|
||||
bd(0)
|
||||
elseif choice == 2 then -- No
|
||||
bd(0, true)
|
||||
end
|
||||
else
|
||||
bd(0)
|
||||
end
|
||||
end,
|
||||
desc = "Delete Buffer",
|
||||
},
|
||||
-- stylua: ignore
|
||||
{ "<leader>bD", function() require("mini.bufremove").delete(0, true) end, desc = "Delete Buffer (Force)" },
|
||||
},
|
||||
},
|
||||
|
||||
-- better diagnostics list and others
|
||||
{
|
||||
"folke/trouble.nvim",
|
||||
|
@ -208,4 +208,43 @@ function M.foldexpr()
|
||||
return "0"
|
||||
end
|
||||
|
||||
function M.bufremove()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
if vim.bo.modified then
|
||||
local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel")
|
||||
if choice == 0 then -- Cancel
|
||||
return
|
||||
end
|
||||
if choice == 1 then -- Yes
|
||||
vim.cmd.write()
|
||||
end
|
||||
end
|
||||
|
||||
for _, win in ipairs(vim.fn.win_findbuf(buf)) do
|
||||
vim.api.nvim_win_call(win, function()
|
||||
if not vim.api.nvim_win_is_valid(win) or vim.api.nvim_win_get_buf(win) ~= buf then
|
||||
return
|
||||
end
|
||||
-- Try using alternate buffer
|
||||
local alt = vim.fn.bufnr("#")
|
||||
if alt ~= buf and vim.fn.buflisted(alt) == 1 then
|
||||
vim.api.nvim_win_set_buf(win, alt)
|
||||
return
|
||||
end
|
||||
|
||||
-- Try using previous buffer
|
||||
local has_previous = pcall(vim.cmd, "bprevious")
|
||||
if has_previous and buf ~= vim.api.nvim_win_get_buf(win) then
|
||||
return
|
||||
end
|
||||
|
||||
-- Create new listed buffer
|
||||
local new_buf = vim.api.nvim_create_buf(true, false)
|
||||
vim.api.nvim_win_set_buf(win, new_buf)
|
||||
end)
|
||||
end
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user