Skip to content

Instantly share code, notes, and snippets.

@noahfrederick
Created October 24, 2013 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahfrederick/7130087 to your computer and use it in GitHub Desktop.
Save noahfrederick/7130087 to your computer and use it in GitHub Desktop.
Delete current buffer in Vim without closing its split.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment