Tip #165: Deleting a buffer without closing the window
tip karma |
Rating 16/9, Viewed by 673
|
created: |
|
November 16, 2001 11:50 |
|
complexity: |
|
intermediate |
author: |
|
Raymond Li |
|
as of Vim: |
|
6.0 |
I'm not sure if this functionality is already within Vim, but I sometimes I find it useful to keep a split window from closing when deleting a buffer. This has already been discussed on the [email protected] mailing list. However, I feel this solution is a little easier to use.
" Put this into .vimrc or make it a plugin.
" Mapping :Bclose to some keystroke would probably be more useful.
" I like the way buflisted() behaves, but some may like the behavior
" of other buffer testing functions.
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete ".l:currentBufNum)
endif
endfunction
<<Make non-ASCII characters displayed on console |
Mapping caps lock to esc in XWindows >>
Additional Notes
|