I’m a huge fan of Microsoft’s Visual Studio Code but the one thing that I found was missing when switching from Sublime Text is the inability to open any file with it by using the context menu.
Adding this functionality can be done with a simply registry tweak.
- Open the registry by pressing [WIN]+[R} and typing regedit
- Navigate to
HKEY_CLASSES_ROOT\*\shell
and add a key with the text you want to appear in the context menu. For example: “Open with VS Code” - Create a new key inside this called “command”
- Modify the default value in “command” to
C:\Program Files (x86)\Microsoft VS Code\Code.exe "%1"
. - To clean up the context menu listing a bit, modify the (Default) key in the Open with VS Code folder to
Edit with VS Code
then add an Icon Key by right clicking and selecting New > String Value and adding the following as the value.C:\Program Files (x86)\Microsoft VS Code\Code.exe,0
Follow the steps below to handle opening folders as projects. This is especially helpful when searching through misc code without having to open it up in a full fledged IDE. This is exceptionally helpful when working with more complicated scripting projects such as Python.
- Navigate to
[KHEY_CLASSES_ROOT\Directory\shell
- Create a key and name it vscode.
- Add the text and icon information by doing the same as above by modifying the default string to
Open Folder as VS Code Project
and adding an Icon string targeting"C:\Program Files (x86)\Microsoft VS Code\Code.exe",0
- To properly target VS Code, add a new code under the new vscode folder and name it “command” and adding the following to the default string
"C:\Program Files (x86)\Microsoft VS Code\Code.exe" "%1"
- To support opening the current folder by right-clicking in the white space inside Windows Explorer, navigate to
[HKEY_CLASSES_ROOT\Directory\Background\shell
- Create another folder called “vscode”
- Change the default string to
Open Folder as VS Code Project
- Add a new string, name it “Icon” with the value
"C:\Program Files (x86)\Microsoft VS Code\Code.exe",0
As an alternative, you can copy the below code into an empty text file and rename it as vscode.reg and then run it by double clicking.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
Windows Registry Editor Version 5.00 ; This will handle right clicking on a file [HKEY_CLASSES_ROOT\*\shell\Open with VS Code] @="Edit with VS Code" "Icon"="C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe,0" [HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command] @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%1\"" ; This will handle right clicking on a folder and open that folder ; as a new project [HKEY_CLASSES_ROOT\Directory\shell\vscode] @="Open Folder as VS Code Project" "Icon"="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\",0" [HKEY_CLASSES_ROOT\Directory\shell\vscode\command] @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%1\"" ; This handles the case of right clicking inside of a folder ; to open that folder as a new project [HKEY_CLASSES_ROOT\Directory\Background\shell\vscode] @="Open Folder as VS Code Project" "Icon"="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\",0" [HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command] @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%V\"" |
Thanks for sharing this.
I think you miss one last step
#9 – create a new key name it ‘command’ with value = “C:\Program Files\Microsoft VS Code\Code.exe”, “%V”
For opening in whitespace background make sure to add the command using %V and not %1. Additionally, playing around with quotations fixed this for me & expandable string values for Icon.
Useful, thank you. It is worth noting that you have to check the installation path of vscode, right now, if you install it from the windows store it is located in the appdata folder.