When a buffer gets deleted (the \"bd[elete]\" command), it not only deletes the buffer but also removes the split window that buffer was in.
Is there a way to delete
You can add the following to your .vimrc
to have Bd
work as bd
but without touching the window splits:
command Bd bp\|bd \#
I found this as a useful complement to what Mud answered.
bp|bd #
will do it.
Details:bp
("buffer previous") moves us to a different buffer in the current window (bn
would work, too), then bd #
("buffer delete" "alternate file") deletes the buffer we just moved away from. See: help bp
, help bd
, help alternate-file
.
I actually like the behaviour of :bd
some of the time so I use the following combination:
nmap <silent> <Leader>d :enew \| bd#<Return>
nmap <silent> <Leader>w :bd<CR>
This allows me to use <Leader>d
to close a buffer whilst maintaining splits and <Leader>w
to close a buffer and split simultaneously.
:enew
creates a new buffer and switches focus to itbd #
delete the last buffer that was focusedMy Choice is
:sb # | bd #
:sb 1 | bd #
: <1. Recall Buffer> | <2. Delete Buffer>
Think Like that! /// <1. Recall Buffer> | <2. Delete Buffer>
:vert sb 2 | bd #
:vert sb <tab key~completed file(buffer)name> | bd #
why?! It's easy to remember 3 (+ 1) keyword!
That are easy and very useful in many other many case!
Have a nice Day! :)
See deleting a buffer without closing the window on VIM tips wiki.
I do something similar to @Mud, but switch to previous view buffer, #
, instead of the previous buffer in buffer list. Here is a binding key in my .vimrc
:
nnoremap <silent> <leader>q :lclose<bar>b#<bar>bd #<CR>
Close Location windows, if exist, switch to the previous view buffer, and then close the last switched buffer.