How do I open a file in a new tab in Vim?
Answer
:tabedit
Explanation
Vim's tab pages let you keep separate window layouts open at the same time, each with its own set of splits. Opening a file in a new tab gives it a clean, full-screen workspace without disrupting the splits you already have in other tabs.
How it works
:tabedit {filename}(abbreviated:tabe) opens the named file in a new tab page.:tabeditwith no argument opens a new, empty buffer in a new tab.:tabnewis an alias that does the same thing.- Navigate between tabs with
gt(next tab) andgT(previous tab), or:tabnext/:tabprevious. - Close the current tab with
:tabclose(:tabc).
Example
:tabe config.lua " open config.lua in a new tab
:tabe " open a blank new tab
" Navigate tabs:
gt " go to next tab
gT " go to previous tab
3gt " go to tab number 3
Tips
:tabslists all open tabs and their windows.:tabonlycloses all tabs except the current one.- You can open multiple files in separate tabs at startup:
vim -p file1.txt file2.txt. - Tabs and buffers serve different purposes: buffers hold file content, tabs hold window arrangements. For quick file switching,
:bnext/<C-^>is usually faster; tabs shine when you need isolated screen layouts.