DaleSchool

Buffers, Windows, and Tabs

Beginner20min

Learning Objectives

  • Explain the difference between buffers, windows, and tabs
  • Split the screen with :split and :vsplit
  • Switch buffers with :bnext and :bprev
  • Work across multiple files in parallel

Working Code

Imagine you need to edit index.html and style.css at the same time. Vim lets you split the screen and see both.

:e index.html        ← open index.html
:vs style.css        ← split vertically and open style.css

Your screen splits like this:

┌──────────────┬──────────────┐
│ index.html   │ style.css    │
│              │              │
│ <div>        │ .container { │
│   <h1>       │   margin: 0; │
│   </h1>      │ }            │
│ </div>       │              │
└──────────────┴──────────────┘

Move between left and right with Ctrl+w h (left) and Ctrl+w l (right).

Try It Yourself

Open several files from your terminal:

vim index.html style.css app.js

Once Vim opens, run these in order:

:ls              ← list the open buffers
:bn              ← next buffer (style.css)
:bn              ← next buffer (app.js)
:bp              ← previous buffer (back to style.css)
:b index         ← find buffer by name (partial match works)

Now try splitting the window:

:sp              ← horizontal split (same file)
:vs              ← vertical split (same file)
Ctrl+w j         ← move to the lower window
Ctrl+w k         ← move to the upper window
Ctrl+w =         ← make every window equal size
:close           ← close the current window (buffer survives)

Try tabs as well:

:tabnew app.js   ← open app.js in a new tab
gt               ← next tab
gT               ← previous tab
:tabclose        ← close the current tab

"Why?"

Think of it like papers on a desk.

A buffer is a document spread open on the desk. Open 10 files and you have 10 buffers. Some are out of sight but still in memory. They stay open until you clear them with :bd (buffer delete).

A window is a viewport that displays a buffer. You can show the same buffer in two windows at once. Closing a window (:close) doesn't delete the buffer — it just hides it.

A tab is a workspace. Each tab has its own window layout. You can make a "HTML/CSS tab" and a "JavaScript tab" and switch between them.

Remember the key relationship: it's not buffer ⊃ window ⊃ tab. A tab is a window layout, a window is a view onto a buffer, and a buffer is file content. These three are independent concepts.

Deep Dive

Buffer command reference
CommandAction
:e {file}Open a file into a buffer
:lsList open buffers
:bn / :bpNext / previous buffer
:b {name}Switch to buffer by name (partial match)
:bdDelete the current buffer
:b#Switch to the previously active buffer
Window navigation shortcuts

Press Ctrl+w followed by a direction key.

KeyAction
Ctrl+w hWindow to the left
Ctrl+w jWindow below
Ctrl+w kWindow above
Ctrl+w lWindow to the right
Ctrl+w wNext window (cycles)
Ctrl+w =Equalize window sizes
Ctrl+w _Maximize current window height
Ctrl+w |Maximize current window width

Run through this scenario yourself:

  1. Launch vim (no file).
  2. Open your config with :e ~/.vimrc.
  3. Split vertically with :vs.
  4. In the right window, open :e ~/.bashrc.
  5. Confirm both buffers are open with :ls.
  6. Jump between panes with Ctrl+w h and Ctrl+w l.
  7. Close the current window with :close, then check :ls — the buffer is still alive.

Key takeaway: closing a window does not remove the buffer.

question: What is a buffer in Vim? answers:

question: Which command splits the screen vertically? answers:

question: Does closing a window delete that file's buffer? answers: