Skip to main content

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

:tabnewopen 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" })
gt        → next tab
gT → previous tab
{N}gt → go to tab N (e.g., 3gt → tab 3)
:tabfirstfirst tab
:tablastlast tab
:tabnextnext tab
:tabprev → previous tab

Tab Commands

:tabslist all tabs and their windows
:tabclose :tabcclose current tab
:tabdo {cmd} → run command in all tabs
:tabmove {n}move tab to position N
:tabmove 0move 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

SituationUse
Switching between filesBuffers (:bnext, Telescope)
Two files side by sideWindows (:vs)
Two completely different contextsTabs
A project vs scratch areaTabs

What's Next