Skip to content

@agibsonsw /SortTabs.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ST sort tabs
import sublime, sublime_plugin, os
from operator import itemgetter
class SortTabsCommand(sublime_plugin.TextCommand):
def run(self, edit):
file_views = []
win = self.view.window()
curr_view = win.active_view()
for vw in win.views():
head, tail = os.path.split(vw.file_name())
group, _ = win.get_view_index(vw)
file_views.append((tail.lower(), vw, group))
file_views.sort(key = itemgetter(2, 0))
for index, (_, vw, group) in enumerate(file_views):
if not index:
prev_group = group
moving_index = 0
elif group > prev_group:
moving_index = 0
prev_group = group
else:
moving_index += 1
win.set_view_index(vw, group, moving_index)
win.focus_view(curr_view)
@agibsonsw
Owner

Assign a shortcut key to sort tabs in Sublime Text. Tabs will also be sorted within their groups.

@titoBouzout

Any way to convert this to a full package? Then you can receive pull request.

@agibsonsw
Owner

Do you mean a repo? (I'm fairly new to GitHub - what's a pull request?).

Yes, I'll create a repo, probably this evening. Andy.

@titoBouzout

Nice, that way we can add for example "Sort Tabs" to the "tab context menu" and I don't know, option to automatically sort these? etc etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.