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. In the editor, open up two blank files in new windows using either the :new command or the <C-w>n mapping in normal mode. Once you’ve done this, try running the :tabnew command. You’ll notice that a new tab bar appears at the top of the editor, and that it has two sections. Try running the :tabnew command 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.