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

How do I reorder tab pages in Vim without specifying an absolute position?

Answer

:tabmove +1

Explanation

:tabmove normally takes an absolute position (:tabmove 0 moves the tab to the far left), but it also accepts relative offsets using + and -. This makes it trivial to nudge the current tab left or right without having to count its index — just use :tabmove +1 or :tabmove -1 to shift it one position.

How it works

  • :tabmove +N moves the current tab N positions to the right
  • :tabmove -N moves the current tab N positions to the left
  • :tabmove 0 moves the tab to the first (leftmost) position (absolute)
  • :tabmove $ moves the tab to the last (rightmost) position (absolute)
  • With no argument, :tabmove moves the tab to the last position (same as $)

Example

You have four tabs open and the active tab is in position 2 (0-indexed):

[A] [B] [*C*] [D]

Running :tabmove +1 shifts tab C one position to the right:

[A] [B] [D] [*C*]

Running :tabmove -2 shifts it two positions left:

[*C*] [A] [B] [D]

Tips

  • Map :tabmove -1 and :tabmove +1 to convenient keys for quick reordering (e.g. <leader>[ and <leader>])
  • Relative moves are safer than absolute when you have many tabs and don't remember exact positions
  • Works in combination with :tabdo and other tab commands

Next

How do I combine two recorded macros into one without re-recording them from scratch?