Move view command

Mark Steve Samson 8 years ago updated by Heinrich 8 years ago 2
I checked the API reference and there seems to be no command to move a view's position in the tabs bar. Maybe I just missed it (it's being done by a mouse drag after all...) but if it isn't available yet I would like to request for its addition. I find it more convenient to use Cmd + Shift + { or } to move around the tabs and Cmd + Shift + Left or Right (the keyboard binding I would probably use) to move the tabs' position.
Just threw together something that gives you this functionality:

1) In Preferences -> Key Bindings (User), add this:

  { "keys": ["ctrl+shift+pagedown"], "command": "move_view", "args": {"direction": "right"} },
   { "keys": ["ctrl+shift+pageup"], "command": "move_view", "args": {"direction": "left"}

Inside of the top-level square brackets ([ ]) in the file.

2) Create a folder and file like so:

~/.config/sublime-text-2/Packages/Ola/move_view.py and fill with this contents:

import sublime, sublime_plugin
class MoveView(sublime_plugin.WindowCommand):
 def run(self, direction):
   pkg_name = "move_view"
   window = sublime.active_window()
   view = window.active_view()
   ret = window.get_view_index(view)
   if ret == -1:
   (group, index) = ret
   if group < 0 or index < 0:
   views = window.views_in_group(window.active_group())
   num_views = len(views)
   oldIndex = index
   if direction == "left":
     if index > 0:
       index -= 1
   elif direction == "right":
     if index < num_views - 1:
       index += 1
     print 'Unrecognized direction:',direction+'. Use left or right.'
   if oldIndex != index:
     window.set_view_index(view, group, index)

Guaranteed not bug free.

I've been trying to figure how to do this, thanks for the snippet.