vimtricks.wiki Concise Vim tricks, one at a time.

How do I open a file in a new tab in Vim?

Answer

:tabnew filename

Explanation

The :tabnew filename command opens a file in a new tab page in Vim. Tabs provide a way to organize multiple windows and buffers into separate views, similar to tabs in a web browser.

How it works

  • :tabnew filename opens filename in a new tab
  • :tabnew without a filename opens a new tab with an empty buffer
  • :tabe filename is a shorter alias (short for :tabedit)

Example

You are editing main.go and want to open README.md in a separate tab:

:tabnew README.md

Vim creates a new tab showing README.md. The tab bar appears at the top of the screen, listing both tabs.

Navigating between tabs

  • gt — go to the next tab
  • gT — go to the previous tab
  • 3gt — go to tab number 3
  • :tabn — next tab (same as gt)
  • :tabp — previous tab (same as gT)
  • :tabfirst — go to the first tab
  • :tablast — go to the last tab

Tips

  • Use :tabclose or :tabc to close the current tab
  • Use :tabonly or :tabo to close all tabs except the current one
  • Use <C-w>T to move the current split window into its own new tab
  • Use :tabs to list all open tabs and the windows they contain
  • Tabs in Vim are different from tabs in other editors — each Vim tab can contain multiple splits (windows), making them more like "layouts" or "workspaces"
  • Use :tabdo %s/old/new/g to run a substitution command across all open tabs
  • Many users prefer buffers over tabs for file switching, but tabs excel at organizing different tasks or contexts (e.g., one tab for source code, another for tests)

Next

How do I edit multiple lines at once using multiple cursors in Vim?