Rearrange tabs with the mouse in gvim

mousetabsvim

Is there any way in gVim to rearrange tabs by dragging and dropping them with the mouse? The behavior I'm looking for is that similar to tabs in Firefox and Chrome.

I know that it's possible to change tab order using :tabm n but that requires figuring out exactly how many tabs in you'd like to move to. Using the mouse would be more useful for this spatial task.

Any methods to move tabs left/right by one position would also be useful, since one could remap keys and move tabs without thinking too hard.

Best Answer

Here is a function to move a tab to the left one position. Put it in your vimrc file and set up your keys as you see fit (to call it longhand, :execute TabLeft()).

Note that these functions "roll" tabs from first to last and last to first, respectively, so moving the first tab left makes it the last tab, and moving the last tab right makes it the first tab.

function TabLeft()
   let tab_number = tabpagenr() - 1
   if tab_number == 0
      execute "tabm" tabpagenr('$') - 1
   else
      execute "tabm" tab_number - 1
   endif
endfunction

...and to the right

function TabRight()
   let tab_number = tabpagenr() - 1
   let last_tab_number = tabpagenr('$') - 1
   if tab_number == last_tab_number
      execute "tabm" 0
   else
      execute "tabm" tab_number + 1
   endif
endfunction