vimtricks.wiki Concise Vim tricks, one at a time.

How do I move a tab to a different position in the tab bar?

Answer

:tabmove {n}

Explanation

:tabmove {n} repositions the current tab page to index n in the tab bar (0-indexed from the left). This is essential for keeping a clean workspace when tabs accumulate in a disorganised order. You can move tabs to absolute positions, to the first or last slot, or shift them relative to their current position.

How it works

  • :tabmove 0 — move to the first position (leftmost)
  • :tabmove $ — move to the last position (rightmost)
  • :tabmove +1 — shift one place to the right
  • :tabmove -1 — shift one place to the left
  • :tabmove — (no argument) same as :tabmove $, moves to the last position
  • :tabmove {n} — move to the absolute index n

The relative syntax (+N / -N) was added in Vim 7.3 and is the most convenient form for reordering without counting positions.

Example

Suppose you have four tabs open and the third one (index 2) is active:

[ file1 ]  [ file2 ]  [ active* ]  [ file4 ]

Running :tabmove 0 moves the active tab to the front:

[ active* ]  [ file1 ]  [ file2 ]  [ file4 ]

Running :tabmove -1 instead would shift it one spot left:

[ file1 ]  [ active* ]  [ file2 ]  [ file4 ]

Tips

  • You can also drag tabs with the mouse in GUI Vim/Neovim when mouse is enabled
  • To move a specific (not current) tab, first switch to it with {n}gt, then run :tabmove
  • Combine with :tabdo patterns for batch tab management in scripts

Next

How do I search for a character by its ASCII or Unicode code point value in a Vim pattern?