Adding An Icon To The “Edit With Sublime Text 2” Contextual Menu Item

As mentioned elsewhere I’ve totally fallen in love with Sublime Text 2 as an editor. One of the issues I’ve had switching to using it on Windows, though, is the muscle memory I’ve developed for selecting the “Edit With Notepad++” contextual menu option. I think part of the reason I’m having trouble switching is that the Notepad++ item has an icon and, by default, the Sublime Text 2 item does not. Several weeks ago I figured out how to add an icon to the Sublime Text 2 item and it has definitely reduced the number of times I’ve accidentally chosen Notepad++. Better write it down before I forget how I did it…

The basics of what I did were taken from a forum posting which ultimately yielded the information I was looking for, but which presented commands I wasn’t prepared to run unvetted, and presented several different possible actions to take without being obvious which ones ended up being “correct”.

For full disclosure, the steps below worked for me on a Win7 x86_64 machine.

If I were to distill the action I took into a single command, ala the ones presented in the forum, it would be this:

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "C:\Program Files\Sublime Text 2\sublime_text.exe,0"

In truth though I was too chicken to run that actual command without fully understanding what I was doing. So here are the actual steps I took to add the icon:

  • run `regedit` (windows-R -> “regedit” -> enter)
  • Find (ctrl-F) “Open with Sublime Text 2”.
    • On my machine there were two results, one in HKEY_CLASSES_ROOT and one in HKEY_LOCAL_MACHINE. Based on the discussion in the forum post above I chose to use the one in HKEY_LOCAL_MACHINE
  • Find the path to the executable being referenced by clicking on the “command” key under HKEY_LOCAL_MACHINE. It’s the “Data” portion of the Default key, minus the %1.
    • On my machine it was “C:\Program Files\Sublime Text 2\sublime_text.exe”
  • Add new key:
    • select “Open with Sublime Text 2”
    • Choose the Edit->New->Expandable String Value menu item
    • Change name of new entry to “Icon”
    • Right click new value, select modify
    • Enter the value you picked up from the command key into the “Value data” field, with “,0” added to the end
      • Example: “C:\Program Files\Sublime Text 2\sublime_text.exe,0”
    • Click “OK”
  • Exit regedit

After those steps, you should have an Icon next to the “Edit with Sublime Text 2” contextual menu item, like so:

4 thoughts on “Adding An Icon To The “Edit With Sublime Text 2” Contextual Menu Item

  1. How do you print a document in ST2? There is no print feature which is such a fundamental feature! What could be the logic to leave it out?

    Anyway, please suggest a way to print documents, selections of documents, etc.

    Thanks

  2. Wow. I never realized you can’t print natively from ST2. Shows how much I print I guess.

    Looks like the most common solution if you just want to print the text is to open it in your platform’s native text editor (notepad, textedit, etc) and print. If you are wanting to print with syntax highlighting, There are a couple of plugins that will export the view to HTML, which you can then print (eg https://github.com/facelessuser/ExportHtml). That sems pretty inconvient if you need to print a lot, but like I said, I never even noticed…

  3. Great post! I was looking exactly for this (and for your same reasons), so googled “sublime text contextual menu icon” and BAM! Kudos :)

Leave a Reply

Your email address will not be published. Required fields are marked *