nvim-bufdel icon indicating copy to clipboard operation
nvim-bufdel copied to clipboard

Feature Request: Add command to delete all buffers except "loaded" buffers

Open iamhrigved opened this issue 1 year ago • 0 comments

If suppose I have many splits open and want to delete the useless buffers which are not currently in use (loaded). There must be a command to do this. I think this plugin will be "complete" if this is implemented.

I tried to do something like this

-- save and delete all unloaded buffers
local bufs = vim.api.nvim_list_bufs()
for _, buf in ipairs(bufs) do
    local modifiable = vim.api.nvim_buf_get_option(buf, "modifiable")
    if modifiable then
	vim.cmd("silent w")
    end
    if not vim.api.nvim_buf_is_loaded(buf) then
	vim.api.nvim_buf_delete(buf, { force = true })
    end
end

I don't know why, but it's not working :/

It would be great if you look into this and try to implement this functionality :)

iamhrigved avatar Jul 05 '24 02:07 iamhrigved