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
:tabnewor:tabnew {file}opens a new tab page (optionally with a file):tabe {file}(short for:tabedit) opens a file in a new tabgtmoves to the next tab pagegTmoves to the previous tab page{N}gtjumps directly to tab number N (1-indexed):tabcloseor:tabccloses the current tab:tabonlyor:tabocloses 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
:tabsto list all open tab pages and their contents :tabmove Nmoves the current tab to position N (0-indexed) —:tabmove 0makes it the first tab,:tabmove $makes it the last<C-w>Tmoves 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/gesubstitutes across all tabs - Map tab navigation for convenience:
nnoremap <C-Tab> gtandnnoremap <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