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

How do I use tab pages in Vim to organize multiple files?

Answer

:tabnew / gt / gT

Explanation

Vim's tab pages let you organize your workspace into separate views, each containing its own window layout. Unlike browser tabs that map to single files, a Vim tab page is a viewport — each tab can hold multiple splits and buffers. Once you learn the core commands, tabs become a powerful way to separate concerns during editing sessions.

How it works

  • :tabnew or :tabnew {file} opens a new tab page (optionally with a file)
  • :tabe {file} (short for :tabedit) opens a file in a new tab
  • gt moves to the next tab page
  • gT moves to the previous tab page
  • {N}gt jumps directly to tab number N (1-indexed)
  • :tabclose or :tabc closes the current tab
  • :tabonly or :tabo closes all tabs except the current one

Example

A typical workflow — you're editing main.go and want to reference a config file in a separate tab:

:tabe config.yaml

Now you have two tabs. Press gT to go back to main.go, or gt to return to config.yaml. Open a third tab for tests:

:tabe main_test.go

Jump directly to the first tab with 1gt, the second with 2gt, or the third with 3gt.

Each tab can have its own splits:

:vsplit utils.go

Now the current tab has two side-by-side windows, while the other tabs remain untouched.

Tips

  • Use :tabs to list all open tab pages and their contents
  • :tabmove N moves the current tab to position N (0-indexed) — :tabmove 0 makes it the first tab, :tabmove $ makes it the last
  • <C-w>T moves the current window into a new tab — great when a split deserves its own workspace
  • Use :tabdo {cmd} to run a command in every tab: :tabdo %s/old/new/ge substitutes across all tabs
  • Map tab navigation for convenience: nnoremap <C-Tab> gt and nnoremap <C-S-Tab> gT (terminal support varies)
  • Tabs are best used for separate contexts (e.g., source code vs. tests vs. docs), not as a 1:1 file-to-tab mapping — use buffers and splits for individual files within each tab
  • Open files from the command line directly into tabs: vim -p file1.go file2.go file3.go
  • Use :tab help {topic} to open a help page in its own tab instead of a split

Next

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