vim-bbye icon indicating copy to clipboard operation
vim-bbye copied to clipboard

Prevent <C-*> from going back to a deleted buffer?

Open fictionic opened this issue 6 years ago • 3 comments

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!

fictionic avatar May 04 '18 17:05 fictionic

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?

moll avatar May 04 '18 17:05 moll

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?

fictionic avatar May 05 '18 17:05 fictionic

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.)

rddunphy avatar Feb 03 '23 12:02 rddunphy