How to open any folder with Sublime Text 3 in Windows.
Tags: tutorial, beginners, windows, registry
Published: 2021-06-20 09:48:48

## 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`

4. Inside the `shell` folder, create a new key and call it: "Open with Sublime Text 3" (or whatever you'd like to call it)
5. Make another new key inside of this and call it: "command"
6. **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.

7. Test it in any folder you like.
8. 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 ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3nmdlzy05wm1skkp3wqz.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j8uliw9rnvgtmv2urbd3.gif) 

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdwgn80jbetzbcrjybrj.gif)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/doopy2o1c82b0wrt2ztu.png)

![Image pointing to * folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rm2is86vgte34a9tac70.png)

![Image pointing to shell folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4552my408aq8rla6orf.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ncrn7t3ikx0643esy84.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jlirnl91lwkjnopspi6.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x692qhltjp9gdju40if.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8xy8x65vthdtj1497np.png)

**After:**
![Rename of Sublime Text 3 registry key to dev.to](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdn7fg6nh7d10063ge5j.png)

**Result:**
![Open with dev.to](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1q27ye03f7k3mawbuq1.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvwn49mwxf3unnwsnh9j.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qo41rntbdm23nbaku9h.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qbz1n5f8uvttvmknjbg.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hr16y6l3s0if9zld8bn9.png)

Now double click **(Default)** or right click **Modify** to edit the data value of this new key.
![Editing the value for (Default)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96hwqyixfc2dxrab1916.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jyrfgy5m1d3440m3arlv.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ywtrxku210t4kxxdb8n.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dsyw0isveoo7nfn62uxb.gif)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3nvksap9o3ocz4pxdlr.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20036h8wc7bssaw9dqp6.png)

**Result**
![Open with Sublime Text 3 in Icon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh6s3bmyg8xjuxiur9db.png)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpopidonzjbr1mdbcv6t.png)

2. Call it: `Position`

3. Set it to the value to:

`Top`

**Result**
![Top position of new context menu item](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/et7odmf0zuetn1qhs5jr.png)

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

`Bottom`

**Result**
![Bottom position of new context menu item](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74pp4xxf3s1jqrx2oxsf.png)




## 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](https://stackoverflow.com/questions/3681032/set-icon-for-custom-right-click-context-menu-item-for-all-desktop-shortcuts-win) 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](https://www.techspot.com/guides/1670-windows-right-click-menu/) article going a bit more in depth with images and pointing myself the right direction to really flesh things out. 

* To this [Livewire](https://www.lifewire.com/what-is-a-registry-key-2625999) 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](https://en.wikipedia.org/wiki/Microsoft_Windows)

![Screenshot of windows](https://i.ytimg.com/vi/OIak121q5tw/maxresdefault.jpg "Screenshot of windows")

- Context menu: A small box/menu that appears when you right click anywhere in a Windows operating system.
![Context menu](https://upload.wikimedia.org/wikipedia/en/thumb/5/50/Context_menu_windows.png/233px-Context_menu_windows.png "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 explainion](https://www.lifewire.com/windows-registry-2625992)![Windows registry](https://www.lifewire.com/thmb/axTOzZb0hVO9ZZFJ2n7WWeq6C_Y=/1002x0/filters:no_upscale():max_bytes(150000):strip_icc():format(webp)/registry-hives-windows-10-5a466683beba330037a4057a.PNG "Windows registry")

- HKEY_CLASSES_ROOT is the global ["hive"](https://www.lifewire.com/hkey-classes-root-2625899)/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](https://www.lifewire.com/what-are-environment-variables-2625868) 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:"