Sunday, May 10, 2015

Customize Sublime Text 3 Context Menu in Windows 7

Edit Context Menu in Sublime Text 3

To change the right-click context menu in Sublime Text 3 and add extra commands one will need to create Context.sublime-menu file with the following general format similar to JSON:

 [
    { "caption": "-", "id": "separator" },
    { "command": "new", "caption": "New" },
    { "command": "open", "caption": "Open" },
    { "caption": "-" }
]


Example: Add the Use Selection for Find and Use Selection for Replace to the Right-click Context Menu



To determine the commands associated with the Use Selection for Find and Use Selection for Replace instructions, first find the hotkeys for the Use Selection for Find and Use Selection for Replace instructions. In the top menubar under Find one sees the hotkeys for Use Selection for Find (Ctrl+E) and Use Selection for Replace (Ctrl+Shift+E).

Open the Default(Windows).sublime-keymap file (Preferences - Key Bindings - Default) and search for Ctrl+E and Ctrl+Shift+E to find  associated commands.

One will find that the commands associated with Ctrl+E (Use Selection for Find) and Ctrl+Shift+E (Use Selection for Replace) are "slurp_find_string" and "slurp_replace_string".

Once the commands are known create a file called Context.sublime-menu in Sublime Text 3's Data\Packages\User directory containing the following:

[
    { "caption": "-" },
    { "command": "slurp_find_string", "caption": "Use Selection for Find" },
    { "command": "slurp_replace_string", "caption": "Use Selection for Replace" },
    { "caption": "-", "id": "end" }
]

Save the file.  Opening the right-click context menu should now show the options Use Selection for Find and Use Selection for Replace

No comments:

Post a Comment