moll / vim-bbye

Delete buffers and close files in Vim without closing your windows or messing up your layout. Like Bclose.vim, but rewritten and well maintained.
http://www.vim.org/scripts/script.php?script_id=4664
Other
654 stars 32 forks source link

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

Open fictionic opened 6 years ago

fictionic commented 6 years ago

I love this plugin, but I often find myself resurrecting deleted buffers by hitting (which I have mapped to <C-*>). Is there a way to fix this? Is https://github.com/moll/vim-bbye/pull/8 relevant? Thanks!

moll commented 6 years ago

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?

fictionic commented 6 years ago

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?

rddunphy commented 1 year ago

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