Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sort the sidebar alphabetically in sublime (ST2)?

Tags:

sublimetext2

I see no option to sort the sidebar in Sublime, how can I do it? I'd like to sort it alphabetically.

like image 956
barlop Avatar asked Dec 23 '13 23:12

barlop


2 Answers

There is a Sublime plugin for that, called SortTabs. It works both with Sublime Text 2 and 3.

You can install it using Sublime Package Manger and then sort tabs using any of the following methods:

  • Sort Tabs by file name
  • Sort Tabs by file type
  • Sort Tabs by file path
  • Sort Tabs by modification date
  • Sort Tabs by last activation
like image 144
Ilia Avatar answered Sep 21 '22 13:09

Ilia


I have found this answer

If you sort the tabs, it sorts the sidebar, and this sorts the tabs

I amended the classname though not to anything better. the classname was probably better before.

{ "keys": ["ctrl+alt+b"], "command": "sorttsortsidebar" }

http://www.sublimetext.com/forum/viewtopic.php?f=4&t=3876&start=20

import sublime_plugin
from os import path
from operator import itemgetter

# A simple command to sort current tabs alphabetically (returning focus to the 
# original tab).
# Does not work with different groups or windows. Not catered for unsaved views 
# (although it seems to work okay if there are any). It could be modified to 
# work in these circumstances.
#   { "keys": ["ctrl+alt+b"], "command": "sort_tabs" },
class SorttsortsidebarCommand(sublime_plugin.WindowCommand):
   def run(self):
      print("ddffd_sorttabs")
      file_views = []
      win = self.window
      curr_view = win.active_view()
      for vw in win.views():
         _, tail = path.split(vw.file_name() or path.sep)
         group, _ = win.get_view_index(vw)
         file_views.append((tail.lower(), vw, group))
      file_views.sort(key = itemgetter(2, 0))
      moving_index = 0
      for index, (_, vw, group) in enumerate(file_views):
         if index == 0 or 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)
like image 39
barlop Avatar answered Sep 21 '22 13:09

barlop