Wiki: Delete Buffer But Hold Window Open


User command :BD

Delete current buffer, but don't close the current window unless there's only one buffer left.

Alternative for built-in :bd

function! s:deleteBufferHoldWindowOpen()
    let bufnum = bufnr("%")
    execute "bn"
    let cmd = bufnum . "bd"
    echo cmd
    execute cmd
endfunction
command! -nargs=0 BD :call <SID>deleteBufferHoldWindowOpen()

If you want delete all buffers without exiting vim, try :BDA

command! -nargs=0 BDALL :1,100bd

works only for up to 100 buffers, though.


Copyright © 2007 RobertMelton.com