DEV Community

Cover image for How to open any folder with Sublime Text 3 in Windows.
John J Davidson
John J Davidson

Posted on

How to open any folder with Sublime Text 3 in Windows.

Introduction:

Hi, this is my first post/tutorial. I hope you enjoy it and find it useful. In this tutorial I will be adding Sublime Text 3 to your right click menu (Context menu), so you can open files/folders in Sublime Text 3, just like you would with VScode.

In this tutorial I am using Windows 10, but you should be able to achieve the same result in Windows 8/8.1 and 7.

TL;DR:

  1. WIN+R keyboard shortcut.
  2. run "regedit.exe".
  3. copy pasting into the address bar at the top:

HKEY_CLASSES_ROOT\Directory\Background

  1. Inside the shell folder, create a new key and call it: "Open with Sublime Text 3" (or whatever you'd like to call it)
  2. Make another new key inside of this and call it: "command"
  3. Modify the key to edit the data value of this new key.

Put the path for your computers version of Sublime Text 3. For me it is:

C:\Program Files\Sublime Text\sublime_text.exe .

Make sure to have a full stop at the end. The full stop as a flag tells windows to open this folder/directory in Sublime Text 3.

  1. Test it in any folder you like.
  2. Done.

P.S A more detailed version of this TL;DR with images can be seen at Step 5.

Step - 1:

In order to edit or add a new item to your right click menu.
You will need edit the Windows Registry to change a setting/registry key for your Windows operating system.

So begin by going to the bottom left of your taskbar and click:
"Start"
Start Icon on the bottom left of your Windows taskbar

Step - 2:

You will need to open/start the Windows "run.exe" and search for the "regedit.exe" in the input field. Once you type that in click "Ok". You can also use WIN+R keyboard shortcut to access "run.exe".

Animate gif of finding and running the Windows run.exe

Step - 3:

Once you run "regedit.exe" you will have a new window appear in front of you. This is called the Registry Editor

⚠️WARNING⚠️ Editing the Windows Registry incorrectly could do damage to your computer's operating system. So please take care from this point forward, and make a back up in case something goes wrong. Thankfully to make a back up is fairly easy.

File > Export > and save the file with what ever name you'd like.
Making a back of the Windows Registry

Step - 4:

Now with your fancy new backup, you can edit your registry with glee.

You now need to navigate to/look for a folder called:
HKEY_CLASSES_ROOT\*\shell\

This should be at the very top of your Registry Editor window.
Image pointing to HKEY_CLASSES_ROOT folder

Image pointing to * folder

Image pointing to shell folder

Now you will see a list of different folders. These should be different for you, depending on what you have installed on your computer.
Image highlighting the shell folder

If you have Sublime Text 3 installed, there should be a folder already here for you to see.
Image pointing to the "Open with Sublime Text 3" folder
To see what this does, look for a file on your computer and right click on it you should see something like this:
Open with Sublime Text 3 on a file

As a test you can edit this file/registry key to change the name and see the change on your right click menu.

Before:
Rename of Sublime Text 3 registry key

After:
Rename of Sublime Text 3 registry key to dev.to

Result:
Open with dev.to

Now you might be asking yourself.

"That's great John, but why should I bother editing something that is already installed by Sublime Text 3?"

I am glad you asked that. Because yes it would seem pointless to edit something for your benefit that is already there. But there is a limit to this "Open with Sublime Text 3" option, that I hope to resolve.

You cannot open a folder of your choice with Sublime Text 3.
Right click menu not showing Open with Sublime Text 3

This isn't provided to you by default or on install. And there was many times I wanted that option. So why not add it now?

Step - 5:

In your Registry Editor lets navigate to a folder called:
HKEY_CLASSES_ROOT\Directory\Background
Navigating to Directory folder

You may notice it's with a a lot of other folders so for speed I recommend typing/copy pasting into the address bar at the top:

HKEY_CLASSES_ROOT\Directory\Background and it should take you right there.

You should now see a shell folder. Lets add a new key to it.
New key in Background/shell folder

Call it: "Open with Sublime Text 3" (or whatever you'd like to call it)

Now make another new key inside of this and call it: "command"
New key and called command

Now double click (Default) or right click Modify to edit the data value of this new key.
Editing the value for (Default)

Now you need to add the system path for your computers version of Sublime Text 3. For me it is:

C:\Program Files\Sublime Text\sublime_text.exe

Your installation might be different.

When you have the path you need to add it to the value like so:
Path to sublime_text.exe

And one very important thing to add at the end of:
C:\Program Files\Sublime Text\sublime_text.exe

is a full stop .

Path to sublime_text.exe with full stop

I know my screen shot above isn't very clear but adding the full stop as a flag tells windows to open this folder/directory in Sublime Text 3.

This is the full path:

C:\Program Files\Sublime Text\sublime_text.exe .

Step - 6:

Now find any folder you wish and right click inside of it to test it out.
Testing out new open with Sublime Text 3

Done 🎉

And this is as far as you need to go, you can now open Sublime Text 3 (or any program you want really) with the right click context menu. Congratulations!

Optional extras 🌟

Adding an Icon:

  1. Right click on the key you created, not command. Just "Open with Sublime Text 3". New > String value
    Adding an icon string value

  2. Call it: Icon

  3. Set it to the same value as the path you set above in Step 5.
    "C:\Program Files\Sublime Text\sublime_text.exe"

Yes with the " " around the path.

Setting the string value

Result
Open with Sublime Text 3 in Icon

Custom position in context menu:

  1. Right click on the key you created, not command. Just "Open with Sublime Text 3". New > String value
    Adding a Position string value

  2. Call it: Position

  3. Set it to the value to:

Top

Result
Top position of new context menu item

  1. If you want the position to be at the bottom. Set the value to:

Bottom

Result
Bottom position of new context menu item

Inspiration:

This post came from my own desire to add Sublime Text 3 to the Windows context menu and open it in any folder I wanted. What I thought would be a simple thing turned out to be fairly difficult for me and a lot of DuckDuckGo later, I am here. This post is my documentation of the process so it's available for me in the future and I hope it is helpful to you. Dear reader. :D

With thanks:

  • To this fantastic stackoverflow question and discussion giving me a lot of help and guidance on how to add an icon to my new context menu item.

  • To this Techspot article going a bit more in depth with images and pointing myself the right direction to really flesh things out.

  • To this Livewire article. Going deep on what a registry key and how to edit them.

Jargon explainer:

  • Windows 7/8/10: Windows is the operating system that is being used in this tutorial, (7/8/10) is the version of the operating system link to Wikipedia article

Screenshot of windows

  • Context menu: A small box/menu that appears when you right click anywhere in a Windows operating system.
    Context menu

  • Windows Registry: The registry in windows is the place that store all of your windows computer software settings. stuff like: hardware devices, user preferences, and operating-system configurations. link to detailed explainionWindows registry

  • HKEY_CLASSES_ROOT is the global "hive"/folder that holds the all the information that effects all users on that computer. Similar to a global variable/root directory that you can edit.

  • Environment variables are surrounded by the percent sign (%), as in %temp%, to distinguish them from regular text. You can reference user variables and system variables as we did in the "Opening the folder with custom file name/date:"

Top comments (1)

Collapse
 
bulletproof2k profile image
Виктор Минин

Thank you very much!