Понимаю, что для автора уже не актуально, но может быть кому-то ещё поможет.
Ответ на qaru.site
Создайте файл vsCodeOpenFolder.reg с этим контентом (если вы не выбрали путь установки по умолчанию, вам необходимо настроить пути в этом файле):
Windows Registry Editor Version 5.00 ; Open files [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 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 (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 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 (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\""
Дважды щелкните его, чтобы создать записи в реестре
Если «Открыть с кодом» не отображается в контекстном меню «Проводник», необходимо перезагрузить систему.
Если вы используете 64-битную или инсайдерскую версию VS Code, измените путь соответственно
Обновите програму переустановкой и добавьте галочки открыть с помощью.
Воспользовался предыдущим вариантом и у меня просто открывался Vs code с последним состоянием (не открывалась папка, в которой находился)
Возможно из-за того что у меня VsCode установлен не в папке по умолчанию, а на другом диске
Решил так:
1. Создал файл vscode.bat c таким содержимым
code -r .
/c
Команда code -r . также работает в консоли и открывает Vs code из папки
2. Зашел в Редактор Реестра (win+R и regedit)
В папке \HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command
значение по умолчанию поменял на путь к vscode.bat (у меня это C:\Users\user\Desktop\vscode.bat), поменяйте его в зависимости где у вас находиться .bat файл
Точно также поменял путь по умолчанию в папке \HKEY_CLASSES_ROOT\Directory\shell\vscode\command
И все заработало!
Теперь при нажатии в контекстном меню Open Folder as VS Code Project на секунду открывается терминал и запускает Vs Code в нужной папке.
Спасибо.
У меня иконка не работала, я просто цифры удалил и все, может у кого то еще будет такое
Это чтоб открывались директории:
Компьютер\HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode
Компьютер\HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\command
Это чтоб открывались файлы:
Компьютер\HKEY_CLASSES_ROOT\*\shell\VSCode
Компьютер\HKEY_CLASSES_ROOT\*\shell\VSCode\command
TLDR
Save this contents to a new .reg
file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\VSCode]
@="Open with Code"
"Icon"="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\""
[HKEY_CLASSES_ROOT\Directory\shell\VSCode\command]
@=hex(2):22,00,25,00,4c,00,6f,00,63,00,61,00,6c,00,41,00,70,00,70,00,44,00,61,\
00,74,00,61,00,25,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,00,\
5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,53,\
00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,00,\
78,00,65,00,22,00,20,00,22,00,25,00,56,00,22,00,00,00
Run the file and that’s it.
Detailed
The answer from @dqureshiumar is correct, if you already checked that option during VS Code installation. But maybe you haven’t checked it and don’t want or can’t reinstall it right now. Or maybe you just need more flexibility about the actions shown when right clicking a folder.
So of course we have a lot of people in comments and/or in other answers here talking about how easy it’s to run the installer again. Yes, it is! Just use this solution if you want to do by hand what the installer will do for you, or use this solution as a learning opportunity to understand better how Windows manage context menu actions on directories, to be able to customize what you want for other use cases.
Disclaimer
Dealing with regedit
can be dangerous. Use it with caution and create a .reg
backup before starting if you’re not so experienced on it.
Instructions
So you are able to create your own folder actions at the Windows Registry:
- Press ⊞ Win + R and type
regedit
. - Navigate to the path
HKEY_CLASSES_ROOT\Directory\shell
. - Right click and create a new
Key
namedvscode
. - At the
(Default)
REG_SZ
, put the desired text, likeOpen with Code
. - Optionally, create an
Icon
key pointing to theCode.exe
path (most likely"C:\Users\%UserName%\AppData\Local\Programs\Microsoft VS Code\Code.exe"
).
At this point, something like this:
Yet inside regedit
, go ahead:
- Create another new
Key
namedcommand
inside thevscode
one. - At the
(Default)
REG_SZ
, put the action to open the current path ("%V"
) based on yourCode.exe
path (most likely"C:\Users\%UserName%\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%V"
).
Now, see something like this:
Finally, go ahead to Windows Explorer and right click any folder:
It’s updated on demand, so you can also play with text, icon and command to try your own custom actions, if you want. The VS Code Command Line Interface reference could be helpful if you want to play with another possibilites, like adding the clicked folder to the current Workspace.
Permission Error
If you try to «Open with Code» a folder from a different drive than your VS Code installation (most likely C:
), maybe you’ll receive an error message starting with «You do not have permission to…». This is because a REG_SZ
record can be wrongly interpreted in cases it contains multiple strings inside the value. Unfortunately the Windows Registry Editor UI doesn’t offer a way to convert REG_SZ
to REG_EXPAND_SZ
on (Default)
keys. If you face this problem, just use my TLDR solution with the hex(2)
value, which will automatically create the REG_EXPAND_SZ
type.
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:
-
Right click on Windows folder and open with Visual Studio Code
-
https://www.howtogeek.com/382727/what-is-a-reg-file-and-how-do-i-open-one/
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
- Pick a username
- Email Address
- Password
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
I’m all about using Visual Studio Code for Node.js development. It is a lightweight code editor and runs on Windows, Mac OS X, and Linux. I enjoy it so much that I also use it for Node.js projects on the Raspberry Pi. To accomplish this, I create a Windows file share on the RasPi as described in my Beginner’s Guide to Installing Node.js on the Raspberry Pi and map a drive on my Windows system to the RasPi. I am then able to use VS Code to create my Node.js code and jump onto the RasPi to run the actual code.
Anyway, back to our regularly scheduled program… Today’s topic is aimed at Windows users who are using Visual Studio Code and want to be able to right click on a given folder and launch VS Code. We’re going to add a right click context menu item to “Open Folder as VS Code Project” since it saves time—and it’s more fun!
Major Edit: It turns out that when you install VS Code for Windows, you have an opportunity to add an “Open with Code” action to the Windows Explorer file context menu—if you don’t hastily sprint through the installation and take the defaults like I did the first time around. 🙂 Take a deep breath and jog rather than scream through the installation. When you see the dialog box below, be sure to check the two checkboxes highlighted.
Ignore the rest of this post unless you don’t want to re-install VS Code or if you are curious for other contexts. It’s easier to simply re-install VS Code.
Let’s make it so. I am leveraging the excellent work of some of my friends on GitHub who created a Windows context menu item for Sublime Text 2/3.
First, create a file with a “.reg” extension. For example, vsCodeOpenFolder.reg
.
You are then positioned to add these contents to the file:
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\""
Next, save the file.
Note: the above .reg file assumes that you installed VS Code in the default location—which will be the case for most people. Adjust accordingly if the Code.exe file is installed in a different folder.
Very nice – we are almost done. Double click on the vsCodeOpenFolder.reg file that you just created.
Windows UAC (User Account Control) will launch and ask you if you want to allow this app to make changes to your PC. Go ahead and click OK so you can merge the registry code contained in the file with the Windows Registry on your computer.
That’s all there is to it! You can now navigate to a folder through Windows Explorer, right click on either the folder icon or in the folder itself, and you will see an option to “Open Folder as VS Code Project”. As a bonus, you can right click on individual files and “Edit with VS Code” as well.
You can now smile at the fact that you’ll have a little more time each day to write amazing code in Node.js/JavaScript or any of the other languages available for use with VS Code.
Follow Dave Johnson on Twitter to stay up to date on the latest tutorials and tech articles.