Vim's Buffers, Windows, and Tabs
by | | level: beginnerTabs are a popular UI paradigm for GUI text editors, browsers, and more. The fact that Vim also has a feature called “tab pages” that looks a lot like tabs from other programs can be a common source of frustration for newcomers. In a typical GUI editor, each tab represents a single document. Vim’s tab pages are not tied to documents at all, but rather contain window layouts. First, some definitions:
- Buffer
- In Vim's parlance a buffer is an in-memory representation of a document, which may or may not correspond to a file on disk. A single buffer can be visible in more than one window at a time, or none at all.
- Window
- A window is a viewport for displaying a buffer. There is always at least one window visible at all times. When you create a new "split" you are creating a window.
- Tab Page
- A tab page is a collection of one or more windows. There is always at least one tab page in existence. (Depending on your
'showtab'
setting you may only see a listing of tabs when you have more than one.)
A Vim session with a couple of tab pages is shown below:
Notice that Buffer 5 is visible in two windows at once, which can be useful if you need to reference two sections of a long file simultaneously, while buffers 4 and 6 are not visible in any windows. The biggest conceptual hurdle to overcome is that buffers are not tied to any UI element; they can come and go from any window in any tab. (But to add to the confusion, certain commands that operate on buffers, such as :bdelete
, can also affect your window layout.)
This system of buffers, windows, and tab pages provides a lot of flexibility in that you can create multiple window layouts, you can view different parts of a buffer at the same time, and juggling 200 buffers is about as manageable as just two.