Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fictionic opened this issue May 4, 2018 · 3 comments
Open

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

fictionic opened this issue May 4, 2018 · 3 comments

Comments

@fictionic
Copy link

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 #8 relevant? Thanks!

@moll
Copy link
Owner

moll commented May 4, 2018

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
Copy link
Author

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
Copy link

rddunphy commented Feb 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants