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

Smart bufkill option? #21

Open
jesseleite opened this issue May 18, 2018 · 1 comment
Open

Smart bufkill option? #21

jesseleite opened this issue May 18, 2018 · 1 comment

Comments

@jesseleite
Copy link

Could be cool if there was a single :SmartClose command that we could map. This command might behave as follows...

  • If there is an active buffer open in the window, perform a :BD (leaving window)
  • If there is no buffer left in window, :bd (closing window)
  • If it's the last window, and there is no buffer left in window, :q (quit vim altogether)

The last fallback option there might be a bit overzealous, but maybe could be handy? What are your thoughts?

@znculee
Copy link

znculee commented Nov 6, 2020

Hi @jesseleite, my workaround is as follows, so that E516: No buffers were deleted can be avoided. I don't like quiting vim accidentally, so I skip your last requested feature.

function! SmartBufKill()
  let active_buffer_count=len(getbufinfo({'buflisted':1}))
  if expand('%:p') != '' && active_buffer_count > 1
    BD
  else
    bd
  endif
endfunction
noremap <silent> <C-c> :call SmartBufKill()<cr>

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

2 participants