Delete all but current buffer

In neovim, is there a builtin for “delete all buffers, except the currently open one” ?

Thanks!

1 Like

There is no one command for deleting all buffers but current one (as far as I know).
But there are scripts that can do this:
In vimscript:

:1,.-bdelete
:.+,$bdelete

In lua

local bufs=vim.api.nvim_list_bufs()
local current_buf=vim.api.nvim_get_current_buf()
for _,i in ipairs(bufs) do
    if i~=current_buf then
        vim.api.nvim_buf_delete(i,{})
    end
end

2 Likes