7

I'm trying to figure out how the vim concept of buffers, windows, and tabs maps onto emacs.

It seems to me that <c-w>s and <c-w>v are roughly equivalent to Emacs C-x 2 and C-x 3. They're not exactly equivalent since vim splits are equally spaced by default and emacs will bisect the current window.

What is the equivalent of C-x 0 (close this window), C-x 1 (close everything except this window) for vim? I'd like to be able to hide the buffers I'm not currently looking it without closing them, so they can still be summoned later with bufexplorer or something similar.

  • 3
    :h CTRL-W_c, :h CTRL-W_o. – Sato Katsura Jun 21 '16 at 5:17
13

By default, Vim will refuse to replace the current buffer with another one if it contains unsaved changes. You'll need to add the option below to your vimrc if you don't want that behavior (and you don't want that):

set hidden

Buffers are Vim's equivalent of documents in other programs. When you switch to another document, you switch to another buffer. This is done with commands like:

:b2            switch to buffer number 2
:b#            switch to previous buffer
:b foo<tab>    switch to buffer with foo in its name + tab completion
...

Windows are a limited abstraction built on top of buffers. They are viewports used to display buffers but they are not and can't be tied to any specific buffer. Switching to a window or closing a window are definitely not the same as switching to buffer or closing a buffer. You can work with windows with the commands listed under :help ctrl-w:

<C-w>s    split current window in two, focus on the new one
<C-w>c    close the current window
<C-w>o    closes all other windows
<C-w>p    switch to previous window
...

Tab pages are another limited abstraction built on windows. They are workspaces designed to contain one or more windows. Like windows, they can't be used as file/document proxies.

See :help windows and :help tab-page for a thorough description.

  • 2
    Luckily, Emacs (something the OP seems to be familiar with) has a similar buffer concept :) – VanLaser Jun 21 '16 at 8:03
4

Close window: Ctrl-w c

Close all other windows: Ctrl-w o, (o for "only")

For more information open vim and enter the command :help window. Look particularly at sections 3 and 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.