DEV Community

Matheus Gomes 👨‍💻
Matheus Gomes 👨‍💻

Posted on

How to open your files with vs code from the context menu on Windows

Hello!

How long it's been since I posted some content? I think about 3 months or so. But hey, here I'm again, with a new thing I learned.

I was on a quest to open a file with vs code and wanted to make it easy and simple, it was when I thought, why not open it from the context menu? For those who don't know, the context menu is the little menu that opens when you click with the right button of the mouse on some empty space of the folder. There you can access some easy features.

Now let's learn how to place your vs code there!

First, I must say, when you are installing vs code you are presented with the option to make it open in the context menu. So if you are installing it now, you can just mark those boxes and you are done!

For those of you who didn't check it when installing, follow me.

First, you will need to create a .reg file, before you freak out, a .reg file is a 'Windows Register File', The Windows Registry is a hierarchical database where Windows and many applications store configuration settings. So, in order to change some configuration on the context menu, we need to make a .reg file.

In this case, we create a .reg file and open it with some text editor (you can use vs code for this). With it open, we need to place this text:

Windows Registry Editor Version 5.00
; Open files
[HKEY_CLASSES_ROOT\*\shell\Open with VS Code]
@="Edit with VS Code"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe,0"
[HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""
; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="Open Folder as VS Code Project"
"Icon"="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\",0"
[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""
; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
@="Open Folder as VS Code Project"
"Icon"="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\",0"
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%V\""
Enter fullscreen mode Exit fullscreen mode

You can see the default installation folders path are placed in the text, if you have another folder in which you installed the vs code, you just need to replace it in the text. Mine was different:

C:\\Users\\mathe\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe
Enter fullscreen mode Exit fullscreen mode

After that, save and double click the file, it will ask you for permissions, you accept accordingly and here we have, a vs code option on the context menu on Windows!

Hope you enjoyed as much as me! Until next time!!

Useful Links that helped me to create this:

Top comments (9)

Collapse
 
aywole profile image
Aywole

Running again the vscode installer this time marking all the checkbox worked for me.

Collapse
 
matheusgomes062 profile image
Matheus Gomes 👨‍💻

Yes, indeed marking all the checkbox usually works, but if you somehow forgot, you can make this way! :)) Thanks for commenting!

Collapse
 
itsalb3rt profile image
Albert E. Hidalgo Taveras

Thanks, again XD

Collapse
 
footballfan141 profile image
Travis

I installed vs code on my new computer with scoop. Your post taught me something new with the Windows registry. :-)

Thanks! :)

Collapse
 
bukanvalen profile image
Valentino Harpa

Thanks! For some odd reason, when installing VS Code from the Ninite installer, the installer defaults to not ticking those 2 boxes. Pretty weird if you ask me

Collapse
 
matheusgomes062 profile image
Matheus Gomes 👨‍💻

Good, it helped you! I never installed vscode by ninite, in my case I forgot to mark the checkbox in the installer. :))

Collapse
 
jamesa profile image
James

Thanks! Ninite didnt do this by default and so I needed this!

Collapse
 
smailove profile image
Smail Liams • Edited

It did not work for me and I do not know how to remove the new cell that appeared
dev-to-uploads.s3.amazonaws.com/up...

Collapse
 
rofii profile image
Rofii

Same problem. I'd recommend people NOT use this method.