Tabs
In Neovim, a tab (tabpage) is a collection of windows — a complete layout. Tabs are best used for separate working contexts (e.g., different projects or tasks), not for switching between individual files.
Different from GUI Editors
In VS Code, a "tab" = one open file. In Neovim, a "tab" = a window layout. Use buffers to switch between files; use tabs to switch between contexts.
Creating Tabs
:tabnew → open a new empty tab
:tabnew filename → open a file in a new tab
:tabe filename → tab edit (same as tabnew)
Keymap:
vim.keymap.set('n', '<leader>tn', ':tabnew<CR>', { desc = "New tab" })
Navigating Tabs
gt → next tab
gT → previous tab
{N}gt → go to tab N (e.g., 3gt → tab 3)
:tabfirst → first tab
:tablast → last tab
:tabnext → next tab
:tabprev → previous tab
Tab Commands
:tabs → list all tabs and their windows
:tabclose :tabc → close current tab
:tabdo {cmd} → run command in all tabs
:tabmove {n} → move tab to position N
:tabmove 0 → move to first position
:tabmove $ → move to last position
Practical Tab Workflow
Scenario: Working on two features simultaneously
Tab 1: "feature-auth"
Left window: auth/login.lua
Right window: tests/auth_test.lua
Tab 2: "feature-api"
Left window: api/routes.lua
Right window: api/handlers.lua
Bottom window: terminal
Navigation:
1gt → switch to auth tab
2gt → switch to api tab
Keymaps for Tab Management
~/.config/nvim/lua/config/keymaps.lua
vim.keymap.set('n', '<leader>tn', ':tabnew<CR>', { desc = "New tab" })
vim.keymap.set('n', '<leader>tc', ':tabclose<CR>', { desc = "Close tab" })
vim.keymap.set('n', '<leader>to', ':tabonly<CR>', { desc = "Close other tabs" })
vim.keymap.set('n', '<leader>1', '1gt', { desc = "Go to tab 1" })
vim.keymap.set('n', '<leader>2', '2gt', { desc = "Go to tab 2" })
vim.keymap.set('n', '<leader>3', '3gt', { desc = "Go to tab 3" })
When to Use Tabs vs Buffers
| Situation | Use |
|---|---|
| Switching between files | Buffers (:bnext, Telescope) |
| Two files side by side | Windows (:vs) |
| Two completely different contexts | Tabs |
| A project vs scratch area | Tabs |