tags:

views:

86

answers:

1

Is there any way in gvim to rearrange tabs by dragging and dropping them with the mouse? This is behavior I love in Firefox and Chrome.

I know you can do :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.

+2  A: 

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_numeber + 1
   endif
endfunction
Jay
Great, I added that to my gvimrc along with this mapping to set ctrl-shift-cursors as my tab movement keys: "map <silent><C-S-Right> :execute TabRight()<CR>"
werkshy