如何增加 Sublime Text 2 中最近文件的数量?

How to increase number of recent files in Sublime Text 2?

目前,Sublime 2 在文件 > 打开最近显示 8 个项目。我希望将其增加一倍到 16。我已经搜索过,但除了增加开放项目列表外,还没有找到任何东西,这不是正确的解决方案,因为我不使用项目。谁能提供帮助?

据我所知,没有任何设置可以控制它。但是,通过修改菜单内容,您可以扩展那里显示的项目数。

为此,您可以按照以下步骤操作:

  • 如果尚未安装PackageResourceViewer,请安装
  • 从命令面板,select PackageResourceViewer: Open Resource
  • Select Default
  • Select Main.sublime-menu 资源

这将打开控制菜单包含内容的文件。在顶部附近,您会看到与此类似的内容:

{
    "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": "-" },
        { "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": "-" },
        { "command": "clear_recent_files", "caption": "Clear Items" }
    ]
},

从这里您可以通过为索引从 8 到 15(因为索引从 0 开始)添加额外的行 open_recent_file 来将最近文件的数量扩展到 16 个,然后保存文件。

附带说明一下,这对 Sublime Text 2 和 Sublime Text 3 都有效。

在 Sublime Text 3 中,这会为 Default/Main.sublime-menu 创建一个包覆盖,Sublime 将使用它来代替菜单的发布版本。如果 ST3 的未来版本以任何方式更新了主菜单,您将不会被告知并且可能会错过其他菜单更改和功能。您可以安装 OverrideAudit,如果发生这种情况,它会警告您。

这也可能是 Sublime Text 2 的一个担忧(尽管 OverrideAudit 仅适用于 ST3,无法在此处帮助您),但 ST2 不太可能进一步更新,因此这可能不会产生任何实际后果。

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

创建这个新文件(我在 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。也许有人可以测试这是否也适用于 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.
        ],
    },
]

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