Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim close window without closing buffer

Tags:

vim

How do I close a window or unsplit without deleting the buffer?

like image 465
Rnet Avatar asked Feb 28 '14 06:02

Rnet


People also ask

How do I stop Vim buffering?

Close buffer named Name (as shown by :ls ). Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).

What is buffer Vim?

Buffers in vim are the in-memory text of files. Your window is a viewport on a buffer. You can switch between open buffers, this is similar to tabs in other editors. Vim does have a concept of tabs too, but they are slightly different, read more about tabs in the Windows section.


3 Answers

A window is a viewport on a buffer. In vim to manage windows it is CTRL+w the leading command, that you can follow with several options (in bold those that answer to your question):

CTRL+w, v: Opens a new vertical split

CTRL+w, s: Opens a new horizontal split

CTRL+w, c: Closes a window but keeps the buffer

CTRL+w, o: Closes other windows, keeps the active window only

CTRL+w, right arrow: Moves the cursor to the window on the right

CTRL+w, r: Moves the current window to the right

CTRL+w, =: Makes all splits equal size

Then, you need to switch the buffers in the windows:

:ls lists all opened buffers

:b5 switches to your 5th buffer

Finally, to open all buffers in a vertical split, use: :vertical sball. Very useful when you open multiple files as buffers after a grep:

grep -rno --exclude-dir={dir1,dir2,dir3} "searchterm" *
vim $(!! -l)

For more info, see the doc: vimdoc.sourceforge.net

like image 92
Joel.O Avatar answered Oct 09 '22 14:10

Joel.O


If you want to edit another buffer in the window, just use :edit / :buf. The current buffer will be replaced, and remains in the buffer list (i.e. it shows up in :ls).

If you want to close the windows split, use :close. The :quit command will work, too, but has the side effect of closing Vim when this is the last window.

In order to leave buffers that have changes, you need

:set hidden

If you know how Vim deals with buffers, this is a recommended option that many users have set.

like image 29
Ingo Karkat Avatar answered Oct 09 '22 16:10

Ingo Karkat


Vim windows are closed using :q.

However, if you don't have another window open, it will exit from Vim. If you do have another window to switch to, only the current window is closed, and buffer remains open. You may need to set hidden.

To close a buffer, you would need to do :bdelete.

You can check if your buffer is open or not by using :buffers.

like image 7
Amadan Avatar answered Oct 09 '22 14:10

Amadan