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​

: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" })
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​

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

In LazyVim​

LazyVim Context

LazyVim fully supports Neovim's built-in tab pages. Because LazyVim uses bufferline.nvim (which makes buffers look like tabs), actual tab pages are often used less frequently. However, when you do use tabs, LazyVim provides dedicated <leader><tab> keymaps.

AspectVanilla NeovimLazyVim
New Tab:tabnew<leader><tab><tab> or <leader><tab>l
Next/Prev Tabgt / gT<leader><tab>] / <leader><tab>[
Close Tab:tabclose<leader><tab>d
First/Last Tab:tabfirst / :tablast<leader><tab>f / <leader><tab>l

What's Next​