C.W.K.
Stream
Lesson 01 of 04 · published

Buffers, Splits, and Tabs

~14 min · vim, buffers, splits, tabs

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Three concepts that get confused constantly

Vim's three layers — buffers, windows, tabs — sound like the same thing but they're not. Once the mental model clicks, working on a real project with dozens of open files becomes natural.

Buffers — the files you've opened

A buffer is a file held in memory. Every file you open with :e or via the command line becomes a buffer. Buffers exist whether or not you can see them; they're the inventory.

Windows (splits) — the views into buffers

A window is a viewport showing one buffer. :sp creates a horizontal split, :vs a vertical one. Each split is a window — and the same buffer can be shown in multiple windows at once.

Tabs — workspaces, not browser tabs

This is the part that confuses everyone. A Vim tab is not a single open file like in a browser. A Vim tab is a collection of windows — a whole workspace layout. Most experienced users don't use tabs much; they prefer many buffers + a few splits in a single tab.

The mental model: buffers are your file inventory, splits are how you currently look at them, tabs are different layouts. Stop thinking in terms of "open tab per file" — that's a browser habit and it's slower than how Vim is designed to work.

Buffer commands you'll actually use

:ls lists open buffers with their numbers and modified states. :b N jumps to buffer N; :b name jumps by partial filename match. :bn / :bp cycle. :bd deletes (closes) the current buffer. :bufdo cmd runs a command in every buffer — useful for save-all (:bufdo w) or replace-all-files (:bufdo %s/old/new/g | w).

Window movement

The Ctrl-w prefix is the gateway to window operations. Ctrl-w h/j/k/l moves between windows in those directions. Ctrl-w = equalizes sizes. Ctrl-w _ maximizes height; Ctrl-w | maximizes width. Ctrl-w o closes all other windows ("only this one"). Ctrl-w q closes the current window.

Code

Buffer commands·vim
:e file.txt        " open file in current window
:ls                " list all buffers
:b 3               " switch to buffer 3 (by number)
:b foo             " switch to buffer matching 'foo' in name
:bn                " next buffer
:bp                " previous buffer
:bd                " delete (close) current buffer
:bd 3              " delete buffer 3
:bufdo w           " run :w on every buffer (save all)
:bufdo %s/old/new/ge | w   " replace + save in every buffer
Splits·vim
:sp                " horizontal split (current buffer)
:sp file.txt       " horizontal split, open file
:vs                " vertical split
:vs file.txt       " vertical split, open file
Ctrl-w h           " move left
Ctrl-w j           " move down
Ctrl-w k           " move up
Ctrl-w l           " move right
Ctrl-w =           " equalize sizes
Ctrl-w _           " max height
Ctrl-w |           " max width
Ctrl-w r           " rotate splits
Ctrl-w o           " only this window (close others)
Ctrl-w q           " close current window
Ctrl-w T           " move current window into a new tab
Tabs (use sparingly)·vim
:tabnew            " new tab
:tabnew file.txt   " new tab with file
gt                 " next tab
gT                 " previous tab
3gt                " go to tab 3
:tabclose          " close current tab
:tabo              " close all other tabs

External links

Exercise

Open three files in one Vim instance: vim a.txt b.txt c.txt. Without exiting, do the following: (1) :ls and read the buffer list, (2) :vs to split vertically, (3) :b 2 in one of the splits to view file 2 there, (4) navigate between the splits with Ctrl-w h / Ctrl-w l, (5) :bufdo w to save all, (6) close one split with Ctrl-w q. Notice how buffers outlive splits.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.