By josh / January 5, 2013

Save your clicks by taking charge of Sublime’s menus

Even though I love the keyboard shortcuts and command palette in Sublime Text, I still occasionally find myself using the menus. Usually this happens when I’m already using the mouse to browse and open file arbitrary files in Finder or Windows Explorer.

But performing some tasks from the menus can be a pain. For example, I might want to set the syntax for a snippet of code I’ve copied from a web page. I always have trouble remembering where the Syntax entry is hidden (it’s under View | Syntax), and once I find the submenu there are tons of languages to scan through before I get to the one I want.

Since most of Sublime’s settings are stored in JSON formatted files, though, it’s easy to remedy this. I’ve to created a entry in the right-click context menu named Syntax that contains just the formats I use day to day, like HTML, CSS, JavaScript and XML. Now all I have to do to set the syntax for a file is right-click in the editor window and make a selection from my custom Syntax menu.

To add this new context menu entry, I created the following file:

/Sublime/Data/Packages/User/Context.sublime-menu

The file name is significant, as it lets Sublime know which menu I’m enhancing.

Then I added the menu configuration code you can see here: https://gist.github.com/4461602

After I saved the file, my new context menu was available instantly—no need to restart Sublime.

You can use a similar approach to add shortcut entries to the application menu and right-click menus in the sidebar and tab area. Here is a list of some of the default menu files:

/Sublime/Data/Packages/Default/Main.sublime-menu
/Sublime/Data/Packages/Default/Side Bar.sublime-menu
/Sublime/Data/Packages/Default/Tab Context.sublime-menu

Bonus tip: If you’re interested in writing plugins, these menu files (along with the .sublime-keymap files) are a good Rosetta Stone for the Sublime API, as they contain the API calls for every item listed in the menus.

P.S. Ready to take the next step to Sublime Text mastery? Go here:

http://sublimetexttips.com/newsletter

About the author

josh

Click here to add a comment

Leave a comment: