Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=2103

This is an improved version of kwbd.vim. It allows you to delete a buffer without closing the window. It meets the following criteria:
This is a mirror of [kwbd.vim](http://www.vim.org/scripts/script.php?script_id=2103)
Further improved by vim-scripts, fancypantalons (check for modified buffer), seb-mueller (bD mapping, docu) and jranke (typos)
https://github.com/vim-scripts/kwbdi.vim
https://github.com/fancypantalons/kwbdi.vim
https://github.com/fancypantalons/kwbdi.vim
https://github.com/seb-mueller/kwbdi.vim

It allows you to delete a buffer without closing the window. It meets the following criteria:

* The window layout must be kept in all circumstances.
* If there is an alternate buffer must be showing that.
* If there is not alternate buffer then must be showing the preious buffer.
* If there is no alternate nor previous buffer (it is the only buffer) must show an empty buffer.
* If there is an alternate buffer, the window must show that instead.
* If there is no alternate buffer then the window must show the previous buffer.
* If there is no alternate nor previous buffer (it is the only buffer) it must show an empty buffer.

If there are two windows with the same buffer open, both windows will remain open, and the buffer will be deleted

To delete a buffer while keeping the window open, just type \bd
To delete a buffer while keeping the window open, just type **<leader>bd**

Thanks to the authors of kwbd.vim and minibufexpl.vim!
55 changes: 55 additions & 0 deletions doc/kwbdi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
*kwbdi.txt* Delete a buffer while keeping the window open

==============================================================================
Introduction *kwbdi*

In order to unload and delete a buffer from the buffer list, :bd is your friend
(:h bd). An often unpleasant side effect is that this also closes the window
changing the window layout.

Kwbdi allows you to delete a buffer without closing the window. It meets the
following criteria:

* The window layout must be kept in all circumstances.
* If there is an alternate buffer, the window must show that instead.
* If there is no alternate buffer then the window must show the previous
buffer.
* If there is no alternate nor previous buffer (it is the only buffer) it
must show an empty buffer.

If there are two windows with the same buffer open, both windows will remain
open, and the buffer will be deleted.

==============================================================================
Usage *kwbdi-usage*

<leader>bd Delete the current buffer while keeping the window open.
Throws an error and doesn't delete the buffer if it is modified
(safe option)

<leader>bD Same as above but changes in the current buffer are discarded
without asking, simulating :bd! (be careful!).

================================================================================
Alternatives *kwbdi-alternatives*

bufkill.vim (http://www.vim.org/scripts/script.php?script_id=1147)

The mapping gives similar behaviour:

:nmap <leader>bd :b#<bar>bd#<CR>

:command Bd bp\|bd \#

Credit for those solutions and contributors of this thread:
https://stackoverflow.com/questions/4298910/vim-close-buffer-but-not-split-window

================================================================================
Credits *kwbdi-credits*

Thanks to the authors of kwbd.vim and minibufexpl.vim!

Improvements by:
Ben Booth https://github.com/vim-scripts/kwbdi.vim
Brett Kosinski https://github.com/fancypantalons/kwbdi.vim
seb-mueller https://github.com/seb-mueller/kwbdi.vim
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kwbdi.txt kwbdi.txt /*kwbdi.txt*
18 changes: 17 additions & 1 deletion plugin/kwbdi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@ let loaded_kwbd = 1

if !hasmapto('<Plug>Kwbd')
map <unique> <Leader>bd <Plug>Kwbd
map <unique> <Leader>bD <Plug>KwbdForce
endif

noremap <unique> <script> <Plug>Kwbd :call <SID>Kwbd(1)<CR>:<BS>
noremap <unique> <script> <Plug>Kwbd :call <SID>KwbdSafe()<CR>:<BS>
noremap <unique> <script> <Plug>KwbdForce :call <SID>KwbdForce()<CR>:<BS>

"delete the buffer; keep windows
function <SID>KwbdSafe()
let g:kwbdBufNum = bufnr("%")
if getbufvar(g:kwbdBufNum, '&modified')
echoerr 'No write since last change for buffer '.bufname('%')
return
endif

call <SID>Kwbd(1)
endfunction

function <SID>KwbdForce()
call <SID>Kwbd(1)
endfunction

function <SID>Kwbd(kwbdStage)
if(a:kwbdStage == 1)
let g:kwbdBufNum = bufnr("%")
Expand Down