【问题标题】:How can I sort the sidebar alphabetically in sublime (ST2)?如何在 sublime (ST2) 中按字母顺序对侧边栏进行排序?
【发布时间】:2013-12-23 23:08:58
【问题描述】:

我看不到在 Sublime 中对侧边栏进行排序的选项,我该怎么做?我想按字母顺序排序。

【问题讨论】:

  • 你的意思是打开文件的列表吗?这是选项卡的顺序,因此您必须重新排列选项卡才能对列表进行排序。
  • @MattDMo 是的,完全正确
  • 我认为现在很多人都使用“Visual Studio Code”,或者其他方式,Atom。
  • Sublime 仍然很受欢迎,并且还在继续开发。 ST4 目前处于“私人测试版” - 最新版本是几天前刚刚发布的。

标签: sublimetext2


【解决方案1】:

为此有一个 Sublime plugin,称为 SortTabs。它适用于 Sublime Text 2 和 3。

您可以使用Sublime Package Manger 安装它,然后使用以下任何一种方法对选项卡进行排序:

  • 按文件名排序选项卡
  • 按文件类型对选项卡进行排序
  • 按文件路径对选项卡进行排序
  • 按修改日期排序标签
  • 按上次激活对标签排序

【讨论】:

  • 通过控制台安装了包管理器,但在“查看”菜单中没有看到任何“按...排序选项卡”选项。它应该在其他地方吗?我在 ST3 上。
  • @Manish 你打开 ST 下拉菜单 (Ctrl+Shift+P) 并输入 sort - 它就会出现! ;)
  • 这不对文件夹进行排序,只对文件名进行排序。
【解决方案2】:

我找到了这个答案

如果你对选项卡进行排序,它会对侧边栏进行排序,这会对选项卡进行排序

我修改了类名,但没有更好。以前的类名可能更好。

{ "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)

【讨论】:

  • 你如何把它变成崇高的?
  • @Omar 很久以前了,但是看看如何编写一个非常基本的插件,例如一个插入文本“hello world”,然后有代码的时候,例如code.tutsplus.com/tutorials/… 并且您知道如何安装它(该链接可能会有所帮助),然后您可以尝试用我的答案中的代码替换它
猜你喜欢
  • 1970-01-01
  • 2015-06-09
  • 1970-01-01
  • 2011-08-29
  • 2010-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多