Created
October 24, 2013 02:00
-
-
Save noahfrederick/7130087 to your computer and use it in GitHub Desktop.
Delete current buffer in Vim without closing its split.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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