【问题标题】:How to increase number of recent files in Sublime Text 3?如何在 Sublime Text 3 中增加最近文件的数量?
【发布时间】:2013-12-30 16:28:37
【问题描述】:

是否可以增加在 Sublime Text 3 (Ubuntu) 中的 File -> Open recent menu 中显示的最近文件的数量?

我已经看过Increase number of recent projects in Sublime Text 2?

我在我的电脑上找不到这个 ~/Library 文件夹。我可以找到 ~/.config/sublime-text-3/Packages 但里面没有“默认”子文件夹。

【问题讨论】:

    标签: sublimetext3


    【解决方案1】:

    Linux 上 Sublime Text 3 中的默认包存储在(假设您使用 .deb 安装程序)/opt/sublime_text/Packages/Default.sublime-package

    Default.sublime-package 是一个 ZIP 文件,如果您打开它并将其中的 Main.sublime-menu 文件解压缩到 ~/.config/sublime-text-3/Packages/Default/Main.sublime-menu,则可以按照链接答案描述的相同方式对其进行编辑。

    或者运行以下命令,这将创建默认目录并将Main.sublime-menu 文件提取到其中:

    mkdir ~/.config/sublime-text-3/Packages/Default/
    unzip -p /opt/sublime_text/Packages/Default.sublime-package Main.sublime-menu > ~/.config/sublime-text-3/Packages/Default/Main.sublime-menu
    

    【讨论】:

    • 编辑:sudo gedit .config/sublime-text-3/Packages/Default/Main.sublime-menu。查找:“标题”:“打开最近”、“助记符”:“R”、“孩子”:只需添加更多行
    • 在 Windows 上:打开%appdata%\Sublime Text 3\Packages,添加Default 目录。按照答案中的说明粘贴编辑后的 ​​Main.sublime-menu。 (是的,您可以将 DOS 环境变量粘贴到文件资源管理器栏和运行...框中。)
    【解决方案2】:

    至少在 OSX 上,Default.sublime-package 位于应用程序本身中:/Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package

    要轻松编辑配置而不在更新时覆盖更改,您需要在 Packages 目录中复制 Main.sublime-menu ~/Library/Application Support/Sublime Text 3/Packages/Default/Main.sublime-menu

    实现这些更改的最简单方法是安装优秀的 skuroda 的 PackageResourceViewer(使用 Package Control),然后:

    1. Command+Shift+p
    2. 输入“资源”并选择“PackageResourceViewer:打开资源
    3. 您会看到可用软件包的列表:选择“默认
    4. 选择'Main.sublime-menu'
    5. PackageResourceViewer 现在将Main.sublime-menu 复制到正确的位置并打开新文件进行编辑(注意:在点击保存之前,该文件似乎并未实际在文件系统中创建,并且更新似乎立即可见,无需更新) .
    6. 根据 Rufus_12 的回答,更改出现的 open_recent_folderopen_recent_file 语句的数量,每次都增加索引。

      { "command": "open_recent_folder", "args": {"index": 0 } },
      { "command": "open_recent_folder", "args": {"index": 1 } },
      { "command": "open_recent_folder", "args": {"index": 2 } },
      { "command": "open_recent_folder", "args": {"index": 3 } },
      { "command": "open_recent_folder", "args": {"index": 4 } },
      { "command": "open_recent_folder", "args": {"index": 5 } },
      { "command": "open_recent_folder", "args": {"index": 6 } },
      ...continue as many times as necessary... 
      

    更新:可维护性

    正如@drevicko 指出的那样,这种方法不会自动更新 Sublime,甚至可能在未来引起冲突。

    @James' answer(编辑 Packages/User/Default/Main.sublime-menus)确实是防更新的,但不幸的是,会导致重复的子菜单(重复的条目出现在我的最底部菜单)。用户设置文件与默认值合并,但会导致重复键。

    我发现如果我更新 Packages/Default/Main.sublime-menus,那么该文件会完全替换默认值(删除块并看到您的菜单实时消失!) - 我的新文件和默认值不会合并。

    为了:a) 避免重复条目,b) 与 Sublime 更新保持同步,我看不到使用 git 跟踪文件更改的替代方法,并且当 Sublime 更新时,重复 Open Resource 过程(覆盖您的编辑),然后仅还原相关更改。

    【讨论】:

    • 谢谢。效果很好。
    • PackageResourceViewer 既实用又简单。 ty
    • 这也适用于项目菜单中的最近文件。在 Main.sublime-menu 中查找“项目”部分。
    • 对于那些想要增加最近项目数量的人,请按照与上述相同的说明进行操作,但使用 { "command": "open_recent_project_or_workspace", "args": {"index": 0 } }, - 在同一个 Main.sublime-menu 中(感谢 @chuckf)
    • 如果未安装 PackageResourceViewer,请转到命令面板 Command + Shift + p,输入 Package Control: Install Package 然后搜索 PackageResourceViewer。 (来自vvvio.com/…
    【解决方案3】:

    在 Windows 7 或 8 上,您:

    1. 在 ZIP/存档实用程序中打开以下文件:
      C:\Program Files\Sublime Text 3\Packages\Default.sublime-package

    2. 仅将文件Main.sublime-menu解压到:
      %APPDATA%\Sublime Text 3\Packages\Default
      (必要时创建文件夹)

      该文件夹也称为:
      C:\Users\YourUsername\AppData\Roaming\Sublime Text 3\Packages\Default

    3. 打开您刚刚提取的 Main.sublime-menu(一个 JSON 文件)并更改出现的 open_recent_folderopen_recent_file 语句的数量,每次都增加索引。

          { "command": "open_recent_folder", "args": {"index": 0 } },
          { "command": "open_recent_folder", "args": {"index": 1 } },
          { "command": "open_recent_folder", "args": {"index": 2 } },
          { "command": "open_recent_folder", "args": {"index": 3 } },
          { "command": "open_recent_folder", "args": {"index": 4 } },
          { "command": "open_recent_folder", "args": {"index": 5 } },
          { "command": "open_recent_folder", "args": {"index": 6 } },
          ...continue as many times as necessary...
      
    4. 点击保存,菜单应立即更新。 :-)

    您甚至可以将您最近使用的文件/文件夹列表移动到根“文件”菜单中,以便于访问。

    【讨论】:

      【解决方案4】:

      对于那些懒得复制粘贴然后更改数字的人,这里有 50 个。

                      { "command": "open_recent_file", "args": {"index": 0 } },
                      { "command": "open_recent_file", "args": {"index": 1 } },
                      { "command": "open_recent_file", "args": {"index": 2 } },
                      { "command": "open_recent_file", "args": {"index": 3 } },
                      { "command": "open_recent_file", "args": {"index": 4 } },
                      { "command": "open_recent_file", "args": {"index": 5 } },
                      { "command": "open_recent_file", "args": {"index": 6 } },
                      { "command": "open_recent_file", "args": {"index": 7 } },
                      { "command": "open_recent_file", "args": {"index": 8 } },
                      { "command": "open_recent_file", "args": {"index": 9 } },
                      { "command": "open_recent_file", "args": {"index": 10 } },
                      { "command": "open_recent_file", "args": {"index": 11 } },
                      { "command": "open_recent_file", "args": {"index": 12 } },
                      { "command": "open_recent_file", "args": {"index": 13 } },
                      { "command": "open_recent_file", "args": {"index": 14 } },
                      { "command": "open_recent_file", "args": {"index": 15 } },
                      { "command": "open_recent_file", "args": {"index": 16 } },
                      { "command": "open_recent_file", "args": {"index": 17 } },
                      { "command": "open_recent_file", "args": {"index": 18 } },
                      { "command": "open_recent_file", "args": {"index": 19 } },
                      { "command": "open_recent_file", "args": {"index": 20 } },
                      { "command": "open_recent_file", "args": {"index": 21 } },
                      { "command": "open_recent_file", "args": {"index": 22 } },
                      { "command": "open_recent_file", "args": {"index": 23 } },
                      { "command": "open_recent_file", "args": {"index": 24 } },
                      { "command": "open_recent_file", "args": {"index": 25 } },
                      { "command": "open_recent_file", "args": {"index": 26 } },
                      { "command": "open_recent_file", "args": {"index": 27 } },
                      { "command": "open_recent_file", "args": {"index": 28 } },
                      { "command": "open_recent_file", "args": {"index": 29 } },
                      { "command": "open_recent_file", "args": {"index": 30 } },
                      { "command": "open_recent_file", "args": {"index": 31 } },
                      { "command": "open_recent_file", "args": {"index": 32 } },
                      { "command": "open_recent_file", "args": {"index": 33 } },
                      { "command": "open_recent_file", "args": {"index": 34 } },
                      { "command": "open_recent_file", "args": {"index": 35 } },
                      { "command": "open_recent_file", "args": {"index": 36 } },
                      { "command": "open_recent_file", "args": {"index": 37 } },
                      { "command": "open_recent_file", "args": {"index": 38 } },
                      { "command": "open_recent_file", "args": {"index": 39 } },
                      { "command": "open_recent_file", "args": {"index": 40 } },
                      { "command": "open_recent_file", "args": {"index": 41 } },
                      { "command": "open_recent_file", "args": {"index": 42 } },
                      { "command": "open_recent_file", "args": {"index": 43 } },
                      { "command": "open_recent_file", "args": {"index": 44 } },
                      { "command": "open_recent_file", "args": {"index": 45 } },
                      { "command": "open_recent_file", "args": {"index": 46 } },
                      { "command": "open_recent_file", "args": {"index": 47 } },
                      { "command": "open_recent_file", "args": {"index": 48 } },
                      { "command": "open_recent_file", "args": {"index": 49 } },
      

      【讨论】:

        【解决方案5】:

        将此Main.sublime-menu 添加到您的%APPDATA%\Sublime Text 3\Packages\User 文件夹。您将看到一个添加的 文件 子菜单,名为 Open Recent More,为您提供下一个相同数量的最近文件/文件夹。 (如果我能把它放在我想要的菜单中。)

        [
            {
                "caption": "File",
                "mnemonic": "F",
                "id": "file",
                "children":
                [
                    {
                        "caption": "Open Recent More",
                        "mnemonic": "R",
                        "children":
                        [
                            { "command": "open_recent_file", "args": {"index": 8 } },
                            { "command": "open_recent_file", "args": {"index": 9 } },
                            { "command": "open_recent_file", "args": {"index": 10 } },
                            { "command": "open_recent_file", "args": {"index": 11 } },
                            { "command": "open_recent_file", "args": {"index": 12 } },
                            { "command": "open_recent_file", "args": {"index": 13 } },
                            { "command": "open_recent_file", "args": {"index": 14 } },
                            { "command": "open_recent_file", "args": {"index": 15 } },
                            { "command": "open_recent_file", "args": {"index": 16 } },
                            { "caption": "-" },
                            { "command": "open_recent_folder", "args": {"index": 8 } },
                            { "command": "open_recent_folder", "args": {"index": 9 } },
                            { "command": "open_recent_folder", "args": {"index": 10 } },
                            { "command": "open_recent_folder", "args": {"index": 11 } },
                            { "command": "open_recent_folder", "args": {"index": 12 } },
                            { "command": "open_recent_folder", "args": {"index": 13 } },
                            { "command": "open_recent_folder", "args": {"index": 14 } },
                            { "command": "open_recent_folder", "args": {"index": 15 } },
                            { "command": "open_recent_folder", "args": {"index": 16 } },
                            { "caption": "-" }
                        ]
                    }
                ]
            }
        ]
        

        【讨论】:

        • 谢谢。它不会取代默认的“打开最近”菜单,但至少这个解决方案不会让我讨厌自己。老实说,这应该是任何想要此功能的人的默认建议。
        • 效果很好!我将它作为符号链接添加到我保存在 Dropbox 中的实际文件。我在某种程度上使它成为“升级证明”的方法,至少如果我升级我的机器并需要重新安装 Sublime。
        【解决方案6】:

        我发现您实际上不需要覆盖主菜单
        只需添加您自己的菜单,该菜单将出现在最后。

        创建这个新文件(我在 linux 中的路径,在 Sublime Text 3 中):
        ~/.config/sublime-text-3/Packages/User/Main.sublime-menu

        在该文件中放入类似于 OdatNurd 先前答案的内容;

        (然后我将相同的内容复制粘贴到文件中:
        Context.sublime-menu
        Side Bar.sublime-menu
        在那里显示相同的子菜单)


        我刚刚从自己的首字母“elm”创建了自己的子菜单,并将我个人使用的所有内容与各种“children”子树一起放在那里。

        作为奖励,它会自动显示其后面相同命令的键盘快捷键
        所以我也用它来提醒我不经常使用并且忘记了键盘快捷键的操作。


        这适用于 Sublime Text 3
        但也许有人可以测试这是否也适用于 Sublime Text 2?


        我的文件如下所示:
        (还添加了更多想法(除了大量最近的文件)以获取灵感)

        [
            {
                "caption" : "elm",
                "mnemonic": "M",
                "children": [
                    {
                        "caption": "Open Recent",
                        "mnemonic": "R",
                        "children": [
                            { "command": "reopen_last_file", "caption": "Reopen Closed File" },
                            { "caption": "-" },
                            { "command": "open_recent_file", "args": {"index": 0 } },
                            { "command": "open_recent_file", "args": {"index": 1 } },
                            // ... etc.
                            { "command": "open_recent_file", "args": {"index": 29 } },
                        ],
                    },
                    {
                        "caption": "Multi Line/Caret editing",
                        "children": [
                            {
                                "caption": "split_selection_into_lines",
                                "command": "split_selection_into_lines",
                            },
                            {
                                "caption": "Add caret above (select_lines)",
                                "command": "select_lines",
                                "args": {"forward": false},
                            },
                            {
                                "caption": "Add caret below (select_lines)",
                                "command": "select_lines",
                                "args": {"forward": true},
                            },
                        ]
                    },
                    {
                        "caption": "Bookmarks",
                        "children": [
                            {
                                "caption": "toggle_bookmark",
                                "command": "toggle_bookmark",
                            },
                            {
                                "caption": "prev_bookmark",
                                "command": "prev_bookmark",
                            },
                            {
                                "caption": "next_bookmark",
                                "command": "next_bookmark",
                            },
                        ]
                    },
                    {
                        "caption": "paste_from_history",
                        "command": "paste_from_history",
                    },
                    {
                        "caption": "Jump to matching bracket",
                        "command": "move_to", "args": {"to": "brackets"},
                    },
                    // ... etc. etc.
                ],
            },
        ]
        

        对于最近的文件有点离题,但我认为这种方法还可以同时提高其他可用性和可维护性方面:)

        【讨论】:

          【解决方案7】:

          我最近来需要这些版本打开文件/文件夹。
          然而,问题是我不想过度填充主菜单。我创建了一个显示其他文件/文件夹的子菜单项。

          除了来自@ptim 和@MoonLite 的上述出色答案之外,我还创建了一个子菜单,以防止它被大量条目过度拥挤。在 Windows 上,路径是(使用自定义 scoop 目录时:C:\app_scoop\apps\sublime-text\current\Data\Packages\Default)。

          我发现您确实可以超载菜单。只需复制出Main.sublime-menu;用下面的代码修改它并将其放入C:\app_scoop\apps\sublime-text\current\Data\Packages\Default,您将拥有带有子菜单的自定义菜单。

          我正在共享一种查看文件/文件夹的子菜单方式(使用目录而不是文件夹来获得更简单的快捷方式 F...文件,D...目录):

           {
                  "caption": "File",
                  "mnemonic": "F",
                  "id": "file",
                  "children":
                  [
                      { "command": "new_file", "caption": "New File", "mnemonic": "N" },
          
                      { "command": "prompt_open_file", "caption": "Open File…", "mnemonic": "O", "platform": "!OSX" },
                      { "command": "prompt_open_folder", "caption": "Open Folder…", "platform": "!OSX" },
                      { "command": "prompt_open", "caption": "Open…", "platform": "OSX" },
                      {
                          "caption": "Open Recent",
                          "mnemonic": "R",
                          "children":
                          [
                              { "command": "reopen_last_file", "caption": "Reopen Closed File" },
                              { "caption": "-" },
                              { "command": "open_recent_file", "args": {"index": 0 } },
                              { "command": "open_recent_file", "args": {"index": 1 } },
                              { "command": "open_recent_file", "args": {"index": 2 } },
                              { "command": "open_recent_file", "args": {"index": 3 } },
                              { "command": "open_recent_file", "args": {"index": 4 } },
                              { "command": "open_recent_file", "args": {"index": 5 } },
                              { "command": "open_recent_file", "args": {"index": 6 } },
                              { "command": "open_recent_file", "args": {"index": 7 } },
                              { "caption": "-" },
                              { "caption": "More Recent Files",
                                "mnemonic": "F",
                                "children":
                                [
                                  { "command": "open_recent_file", "args": {"index": 8 } },
                                  { "command": "open_recent_file", "args": {"index": 9 } },
                                  { "command": "open_recent_file", "args": {"index": 10 } },
                                  { "command": "open_recent_file", "args": {"index": 11 } },
                                  { "command": "open_recent_file", "args": {"index": 12 } },
                                  { "command": "open_recent_file", "args": {"index": 13 } },
                                  { "command": "open_recent_file", "args": {"index": 14 } },
                                  { "command": "open_recent_file", "args": {"index": 15 } },
                                  { "command": "open_recent_file", "args": {"index": 16 } },
                                  { "command": "open_recent_file", "args": {"index": 17 } },
                                  { "command": "open_recent_file", "args": {"index": 18 } },
                                  { "command": "open_recent_file", "args": {"index": 19 } },
                                  { "command": "open_recent_file", "args": {"index": 20 } },
                                ]
                              },
                              { "caption": "-" },
                              { "command": "open_recent_folder", "args": {"index": 0 } },
                              { "command": "open_recent_folder", "args": {"index": 1 } },
                              { "command": "open_recent_folder", "args": {"index": 2 } },
                              { "command": "open_recent_folder", "args": {"index": 3 } },
                              { "command": "open_recent_folder", "args": {"index": 4 } },
                              { "command": "open_recent_folder", "args": {"index": 5 } },
                              { "command": "open_recent_folder", "args": {"index": 6 } },
                              { "command": "open_recent_folder", "args": {"index": 7 } },
                              { "caption": "-" },
                              { "caption": "More Recent Directories",
                                "mnemonic": "D",
                                "children":
                                [
                                  { "command": "open_recent_folder", "args": {"index": 8 } },
                                  { "command": "open_recent_folder", "args": {"index": 9 } },
                                  { "command": "open_recent_folder", "args": {"index": 10 } },
                                  { "command": "open_recent_folder", "args": {"index": 11 } },
                                  { "command": "open_recent_folder", "args": {"index": 12 } },
                                  { "command": "open_recent_folder", "args": {"index": 13 } },
                                  { "command": "open_recent_folder", "args": {"index": 14 } },
                                  { "command": "open_recent_folder", "args": {"index": 15 } },
                                  { "command": "open_recent_folder", "args": {"index": 16 } },
                                  { "command": "open_recent_folder", "args": {"index": 17 } },
                                  { "command": "open_recent_folder", "args": {"index": 18 } },
                                  { "command": "open_recent_folder", "args": {"index": 19 } },
                                  { "command": "open_recent_folder", "args": {"index": 20 } },
                                ]
                              },
                              { "caption": "-" },
                              { "command": "clear_recent_files", "caption": "Clear Items" }
                          ]
                      },
          
          ... (continued)
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2014-12-06
            • 2020-04-24
            • 1970-01-01
            • 1970-01-01
            • 2020-07-20
            • 2013-02-18
            • 2016-11-27
            相关资源
            最近更新 更多