Add ‘Open with Sublime Text’ on Windows Explorer Context Menu

When you do coding in web development, of course, you would also need a text editor that will suit your needs. There are lot free source code editor such as Notepad++, Atom, Coda, Visual Studio Code, Sublime Text and more.

There are two of the editors mentioned above that I really love, namely VS Code and Sublime Text.

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform – Linux, Mac OSX, and Windows.

Sublime Text is a sophisticated text editor for code, markup and prose. You’ll love the slick user interface, extraordinary features and amazing performance.

While I love them both, I always use Sublime Text to do simple editing. Though you’d always have to click on the close button of the pop-up that asks you to buy the text editor. As I’ve mentioned this text editor is free unless you want to get rid of that window that pops up from time to time.

What I really need most is the ability to open Sublime Text by accessing it in the Windows Explorer Context Menu when right-clicking on the known file types and directories. This can be achieved by adding few keys and commands in the Windows Registry.

The following batch file code allows you to open known file types, folders and the currently open folder with Sublime Text 3 from Windows explorer context menu. This has been tested in Windows 7 and Windows 10.

@echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe

rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3"         /t REG_SZ /v "" /d "Open with Sublime" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3"         /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f

rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3"         /t REG_SZ /v "" /d "Open with Sublime" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3"         /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f

rem add it for current folder
@reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3"         /t REG_SZ /v "" /d "Open with Sublime" /f
@reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3"         /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%v\"" /f

pause

Copy the command line script above and paste in your text editor then save it on your desktop as “OpenWithSublimeText.bat”.

Locate the file you saved on your desktop, right-click on it and choose “Run as Administrator”. That should run the script with an elevated privileges.

Now, try right clicking on any file or folder and see if  “Open with Sublime” is successfully added.

Add comment

E-mail is already registered on the site. Please use the Login form or enter another.

You entered an incorrect username or password

Sorry, you must be logged in to post a comment.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Done