Step 1 of 6

13. Tabpages

Tabpages are collection of windows

In the last lesson on windows, I prefaced the first section with a small warning… and I’d like to say a very similar thing again here! In Vim, tabpages are not really comparable to the tabs that you might be familiar with in other editors. It’s better if you try to forget what you know about tabs before working through this lesson. I’ll show you that, despite their confusing name, tabpages are an immensely valuable addition to your Vim arsenal.

So — what is a tabpage? A tabpage is just a collection of windows. In the last lesson we learned how to carve up our screen into windows so that we can keep multiple files in view at the same time. This is great — we can fit a lot more useful content on the screen! But what do you do when you run out of space for more windows? That’s where tabpages come in.

A tabpage is a container that holds one or more windows. With tabpages, you can have multiple window arrangements set up within the same Vim session. You might, for example, have two or three different tabpages, each with their own window layout, to work on different projects. They’re also a nice way to quickly edit a new buffer without altering the current window layout.

Let’s get a taste of what tabpages are first. Work through the checklist below. Open up two blank files in new windows with the :new command — Vim also has a <C-w>n mapping in normal mode that does the same thing, but type the command out in full here. Once you’ve done this, run the :tabnew command. You’ll notice that a new tab bar appears at the top of the editor, and that it has two sections. Run :tabnew again to create yet another tab.

We’ll go over what we just did there in the coming sections — but for now, it’s good to know what it looks like when you create a new tabpage.

  1. Open a new window The screen splits, with a new empty window on top — type :new and hit Enter.
  2. Open another new window A third window joins the stack — type :new and hit Enter.
  3. Create a new tabpage A tab bar appears at the top of the editor, with two sections — type :tabnew and hit Enter.
  4. Create another tabpage The tab bar grows a third section — type :tabnew and hit Enter.
Open a new window The screen splits, with a new empty window on top — type :new and hit Enter.

Next: Open another new window

Loading editor…