public
Created

Delete current buffer in Vim without closing its split.

  • Download Gist
bdelete.vim
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
function! s:Bdelete(bang) abort
let l:current_buffer = bufnr("%")
let l:alternate_buffer = bufnr("#")
 
if buflisted(l:alternate_buffer)
execute "buffer" . a:bang . " #"
else
execute "bnext" . a:bang
endif
 
if bufnr("%") == l:current_buffer
new
endif
 
if buflisted(l:current_buffer)
execute "bdelete" . a:bang . " " . l:current_buffer
endif
endfunction
 
if !exists(":Bdelete")
command -bang -bar Bdelete call <SID>Bdelete(<q-bang>)
endif

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.