vim-bbye
vim-bbye copied to clipboard
Prevent <C-*> from going back to a deleted buffer?
I love this plugin, but I often find myself resurrecting deleted buffers by hitting <BS> (which I have mapped to <C-*>). Is there a way to fix this? Is https://github.com/moll/vim-bbye/pull/8 relevant? Thanks!
Hey,
I think #8 would be for more esoteric use cases. For your particular, however, I think :Bwipeout would do the trick: https://github.com/moll/vim-bbye#buffer-delete-vs-wipeout. Does that help?
Yeah that works, thanks! Except ideally I'd want <C-*>
not to just complain that there's no alternate buffer, but to take me to the next available buffer or something. Is that possible, or does vim not let you dynamically set the alternate buffer?
For anyone else looking for a solution, one alternative is to override <C-^>
to call a custom function like this:
function! OpenLastUsedBuffer(count) abort
let blist = map(sort(getbufinfo({'buflisted': 1}), {b1, b2 -> b2.lastused - b1.lastused}), 'v:val.bufnr')
let idx = min([len(blist)-1, a:count])
execute "buffer ".blist[idx]
endfunction
nnoremap <silent> <C-^> :<C-U>call OpenLastUsedBuffer(v:count1)<CR>
(This works with :Bdelete
as well as :Bwipeout
.)