51
votes

Is it possible to increase the number of recent files that appear in the File -> Open recent menu in Sublime Text 3 (Ubuntu)?

I have already read Increase number of recent projects in Sublime Text 2?

And I can't find this ~/Library folder at my PC. I can find ~/.config/sublime-text-3/Packages but there's no "Default" subfolder inside.

7

7 Answers

77
votes

On OSX, at least, the Default.sublime-package is in the application itself: /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package.

To edit the config easily without changes being overwritten on update, you need a copy of Main.sublime-menu in your Packages directory ~/Library/Application Support/Sublime Text 3/Packages/Default/Main.sublime-menu

The easiest way to effect these changes is to install the excellent PackageResourceViewer by skuroda (using Package Control), then:

  1. Command+Shift+p
  2. type 'resource' and select 'PackageResourceViewer: Open resource'
  3. you see a list of available packages: select 'Default'
  4. select 'Main.sublime-menu'
  5. PackageResourceViewer now copies Main.sublime-menu into the correct location and opens the new file for editing (note: the file doesn't seem to be actually created in the filesystem until hitting save, and updates seem immediately visible without requiring an update).
  6. As per Rufus_12's answer, alter the number of open_recent_folder and open_recent_file statements that appear, increasing the index each time.

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

Update re: maintainability

As @drevicko points out, this method will not auto-update with Sublime, and may even cause conflicts in future.

@James' answer (editing the Packages/User/Default/Main.sublime-menus) is indeed update-proof, but does, unfortunately, result in a duplicate sub-menu (the duplicate entries appear for me at the very bottom of the menu). The user settings file is merged with the defaults, but in a manner which results in duplicate keys.

I find that if I update Packages/Default/Main.sublime-menus, then that file completely replaces the default (delete chunks and see your menus disappear in real time!) - my new file and the defaults are not merged.

In order to: a) avoid a duplicate entry, and b) stay current with Sublime updates, I can't see an alternative to tracking changes to the file using git, and when Sublime updates, repeating the Open Resource process (overwriting your edits), then reverting only relevant changes.

27
votes

The Default package in Sublime Text 3 on Linux is stored in (assuming you used the .deb installer) /opt/sublime_text/Packages/Default.sublime-package.

Default.sublime-package is a ZIP file, if you open it and extract the Main.sublime-menu file from it into ~/.config/sublime-text-3/Packages/Default/Main.sublime-menu, it can then be edited the same way as the linked answer describes.

Alternatively run following commands which will create the Default directory and extract the Main.sublime-menu file into it:

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
17
votes

Add this Main.sublime-menu to your %APPDATA%\Sublime Text 3\Packages\User folder. You will see an added File Menu child named Open Recent More, giving you the next same-amount of recent files/folders. (If only I could position it in the menu where I want it, though.)

[
    {
        "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": "-" }
                ]
            }
        ]
    }
]
10
votes

For those of you who are too lazy to copy and paste then change the numbers, here is 50 of them.

                { "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 } },
6
votes

On Windows 7 or 8 you:

  1. Open the following file in a ZIP/archive utility:
    C:\Program Files\Sublime Text 3\Packages\Default.sublime-package

  2. Extract only the file Main.sublime-menu into:
    %APPDATA%\Sublime Text 3\Packages\Default
    (Create the folder if necessary)

    The folder is otherwise known as:
    C:\Users\YourUsername\AppData\Roaming\Sublime Text 3\Packages\Default

  3. Open Main.sublime-menu (a JSON file) that you just extracted and alter the number of open_recent_folder and open_recent_file statements that appear, increasing the index each time.

        { "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. Hit save and the menu should be instantly updated. :-)

You can even move your recent file/folder list into the root "File" menu for easier access.

3
votes

I found you don't actually need to override the main menu;
just add your own menu which will appear in the end.

Create this new file (path for me in linux, in Sublime Text 3):
~/.config/sublime-text-3/Packages/User/Main.sublime-menu

In that file put something similar to OdatNurd previous answer;

(and I copy paste the same content into the files:
Context.sublime-menu
Side Bar.sublime-menu
to have the same submenu show up there)


I just made my own submenu from my own initials "elm" and put all stuff I personally use there with various "children" subtrees.

As a bonus, it will automatically show keyboard shortcuts to the same command behind it,
so I also use it as a reminder for actions that I don't use very often and forget the keyboard shortcut of.


This works for Sublime Text 3,
but perhaps someone can test if this also works for Sublime Text 2?


My file looks something like this:
(also added some more ideas (beside plenty recent files) for inspiration)

[
    {
        "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.
        ],
    },
]

Bit off topic for just more recent files, but I thought this approach might also improve other usability and maintainability aspects at the same time :)

1
votes

I have come recently to need these edition open files/folders.
However, the catch is that I did not want to over-fill the main menu. I have created a submenu item which shows the other files/folders.

In addtion to above excelent answers from @ptim and @MoonLite, I have created a submenus which prevents overcrowding it with numerous entries. On windows the path is (when using custom scoop directory: C:\app_scoop\apps\sublime-text\current\Data\Packages\Default).

I have found out that you can acutally overload the menu. Just copy out the Main.sublime-menu; modify it with below code and place it into C:\app_scoop\apps\sublime-text\current\Data\Packages\Default and you will have custom menu with submenus.

I'm sharing a submenu way to view the files/folders (using Directories instead of Folders to have easier shortcut F... Files, D ... directories):

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