Step 2 of 6

13. Tabpages

Other ways to create new tabpages

:tabnew creates a tab with a new, blank file opened. You can also use :tabedit — much in the same way as you would use :edit — to open a file in a new tab.

But here’s a really useful trick: if you prefix any command that would ordinarily open a new window with the :tab command, it’ll open that window as a new tabpage instead. For instance:

  • the :split command opens a new horizontally split window peering into the same buffer
  • the :tab split command therefore opens a new tabpage whose window is peering into the same buffer

That particular command — :tab sp — is really handy. It lets you “zoom in” on a singular window by opening it in a new tabpage. I use this to “break flow” and wander off somewhere else in a project, safe in the knowledge that I can return to my previous tabpage later.

Let’s try these in the editor. Work through the checklist below. There are a few files here, called dog.txt, cat.txt, and mouse.txt. First, try opening them in new tabpages with the :tabedit command. For example: to open cat.txt in a new tabpage, you’ll want to write :tabedit cat.txt.

Once you’re used to the :tabedit command, let’s experiment with :tab sp. In your current tabpage, run :args dog.txt cat.txt mouse.txt followed by :all to open all three files in splits. Then, move your cursor to any of the splits and run :tab sp. You should see the window be “broken out” into its own tabpage!

  1. Open dog.txt in a new tabpage A new tabpage appears with dog.txt loaded in it — type :tabedit dog.txt and hit Enter.
  2. Open cat.txt the same way Another tabpage joins the tabline — type :tabedit cat.txt and hit Enter.
  3. And mouse.txt One more — type :tabedit mouse.txt and hit Enter.
  4. Load all three files into the argument list This hands Vim the list of files you're working on — type :args dog.txt cat.txt mouse.txt and hit Enter.
  5. Open the argument list in splits The current tabpage splits into one window per file — type :all and hit Enter.
  6. Break the current window out into a tabpage The window under your cursor gets "zoomed" into a brand new tabpage — type :tab sp and hit Enter.
Open dog.txt in a new tabpage A new tabpage appears with dog.txt loaded in it — type :tabedit dog.txt and hit Enter.

Next: Open cat.txt the same way

Loading editor…