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

Smart bufkill option?

Open jesseleite opened this issue 6 years ago • 1 comments

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?

jesseleite avatar May 18 '18 21:05 jesseleite

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>

znculee avatar Nov 06 '20 01:11 znculee