Joe Gurr

Vim

Buffers

A buffer directly matches an open file in memory (i.e. the content of a tab in a standard IDE).

The big difference is that when you close a tab in a standard IDE you close the file as well. Not in Vim, if you close a window containing a buffer, the buffer is still there, hidden.

A buffer can be in one of three states:

  1. active - displayed in a window
  2. hidden - not displayed, but it exists and the file is still open
  3. inactive - not displayed and is empty

:buffers of :ls lists all of the buffers

To navigate through the buffer list:

  • :buffer {id or name}
  • :bnext or :bn
  • :bprev or :bp
  • :bfirst or :bf
  • :blast or :bl

Buffers are created automatically if you create a window. You can also used :badd {filename}.

:bdelete {id or name}, :m,n bdelete, %bdelete are all ways to delete buffers.

Windows

A window in vim is nothing more than a space you can use to display the content of a buffer. Don't forget - when you close the window the buffer stays open.

To create windows you can use the :new command or:

  • CTRL+W s split current window horizontally
  • CTRL+W v split current window vertically
  • CTRL+W n slit current wino horizontally and edit a new file

To move cursor from one window to another you can use CTRL+W j,k,h,l

To move windows:

  • CTRL+W r rotate the windows
  • CTRL+W x exchange with the next window

Resizing windows:

  • CTRL+W = equal size
  • CTRL+W - decrease height
  • CTRL+W + increase height
  • CTRL+W > decrease width
  • CTRL+W < increase width

Tabs

A buffer is an open file, a window is the container for an active buffer. A tab is a container for a bunch of windows. It is a very different concept to that of a tab in a standard IDE.

:tabnew or tabe new tab

:tabclose or :tabc close tab

:tabonly or :tabo close every other tab

gt go to next tab

gT go to previous tab