How do I close a buffer without closing the window?
Answer
:bp | bd #
Explanation
The :bp | bd # command switches to the previous buffer and then deletes the alternate buffer. This effectively closes a buffer while keeping the window open.
How it works
:bpswitches to the previous buffer|chains commands:bd #deletes the buffer you just left- The window remains open showing the previous buffer
Example
You are editing test.go in a split and want to close it without closing the split:
:bp | bd #
The split now shows the previous buffer instead.
Tips
:bdalone closes the buffer and the window if it is the only one:bwwipes the buffer completely (removes from buffer list):set hiddenallows switching buffers without saving- Consider using
:enewto create a new empty buffer in the window