nothing-special-here
nothing-special-here

Reputation: 12568

How to change tabs order in VIM?

Is there a way to change tabs order in Vim (i.e. change the position of the tabs in the tab bar)? For example, let's say my current tabs are in this order:

A | B | C | D

But I would like to switch the position of the tabs to something like:

A | C | B | D

How can I do that?

Upvotes: 56

Views: 12565

Answers (4)

Jerry
Jerry

Reputation: 85

You can use the :tabmove command. Some examples for moving the current tab:

  • :tabm 3 moves the tab past the 3rd tab.
  • :tabm 0 moves the tab to the beginning.
  • :tabm (without a number) moves the tab to the end.
  • :-tabm moves the tab to the left.
  • :+tabm moves the tab to the right.

(I wanted this to be an edit of the accepted answer; however, "Another edit is awaiting approval for this post. Further edits cannot be submitted until the pending edit is reviewed.")

Upvotes: 0

Fisher
Fisher

Reputation: 412

For me -tabmove is not working.

I'm using below command: Ctrl+Shift+PageUp|PageDown.

nmap <C-S-PageUp>   :tabmove -1<cr>
nmap <C-S-PageDown> :tabmove +1<cr>

Upvotes: 4

Sheharyar
Sheharyar

Reputation: 75740

Move Tabs to the Left / Right

To me it makes much more sense to move the tabs to the left or right of their current position instead of first figuring out the exact numerical position I want them at. These simple keymaps do exactly that:

noremap <A-Left>  :-tabmove<cr>
noremap <A-Right> :+tabmove<cr>

Now you'll be able to move the current tab:

  • To the left using: Alt + Left
  • To the right using: Alt + Right

For MacVim, try using M instead of A (i.e. <M-Left>)

Upvotes: 12

Mihai Maruseac
Mihai Maruseac

Reputation: 21435

You can use :tabmove followed by the tab number to move past. For example, :tabmove 3 will make the current tab move past the 3rd. :tabmove 0 moves to the beginning and :tabmove (without a number) moves to the end.

Another way - though not orthodox - is to enable mouse via :set mouse=a and drag-and-drop tabs around. It might look simpler for a start.

Upvotes: 79

Related Questions