How to use Cmder in Visual Studio Code?
At work, there is an enterprise security policy where all executables are only allowed to run out of C:\Program Files
or C:\Program Files (x86)
.
In Visual Studio Code, in settings.json
, using the following settings:
{
"terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\Program Files (x86)\\Cmder\\vendor\\init.bat"
]
}
...on initialization for the integrated terminal, I receive the following error message:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Because of Windows' awesome file/directory naming convention allowing spaces, it is difficult to point to one of the Program File
paths.
VSCode doesn't like it when you escape the space character, and this code gives me the error Invalid escape character in string
. When I try to change the property to this:
{
...
"terminal.integrated.shellArgs.windows": [
"/k C:\\Program\ Files\ (x86)\\Cmder\\vendor\\init.bat"
]
}
...I get the following error message:
'C:\ProgramFiles' is not recognized as an internal or external command,
operable program or batch file.
Lastly, trying to surround the path in quotes like this:
{
...
"terminal.integrated.shellArgs.windows": [
"/k \"C:\\Program Files (x86)\\Cmder\\vendor\\init.bat\""
]
}
...gives me this error message:
'\"C:\Program Files (x86)\Cmder\vendor\init.bat\""' is not recognized as an
internal or external command,
operable program or batch file.
Is there any way to integrate Cmder in VSCode?
After scouring the Internet for answers, I couldn't find a solution, but I figured it out and thought I might post it here for others to see, as I've seen that people from different forums had the same question but there was no answer.
In Windows, there is a /X
for the dir
command, which states:
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
So, doing a dir /X
command on C:\
displays the following:
C:\>dir /X
Volume in drive C is OSDisk
Volume Serial Number is XXXX-XXXX
Directory of C:\
...
08/17/2017 08:02 PM <DIR> PROGRA~1 Program Files
08/09/2017 03:58 PM <DIR> PROGRA~2 Program Files (x86)
...
You can use the directory short name PROGRA~2
to substitute Program Files (x86)
, and have the following settings in your settings.json
for VS Code:
{
"terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\PROGRA~2\\Cmder\\vendor\\init.bat"
]
}
Which does load Cmder successfully in the integrated terminal:
another solution is you can set your cmder location into new path
and just set in your settings.json
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
you can find it on cmder github issue
This is the new method to do that '2021'
related to this article
Step 1: Download Cmder.
Step 2: Save Cmder to C:\ drive
Step 3: Open Settings.json in VSCode (File - Preferences - Settings ...)
Step 4: Enter this parameters:
"terminal.integrated.profiles.windows": {
"Cmder": {
"path": "${env:windir}\\System32\\cmd.exe",
"args": ["/k", "C:\\cmder\\vendor\\bin\\vscode_init.cmd"]
}
},
"terminal.integrated.defaultProfile.windows": "Cmder",
Another approach.
The Cmder team suggests prepending a ^
character before each space in your path, instead of using the 8dot3 naming approach.
Example:
{
"terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\Program Files^ (x86)\\Cmder\\vendor\\init.bat"
]
}
Taken from official Cmder wiki:
Spaces in path
⚠ CAUTION: The command line interpreter in Windows has some issues with spaces in the path, such as
C:\Program Files (x86)\Cmder
. We do not recommended to install Cmder in a path that contains spaces.Instead, we recommend installing Cmder in a path that does not contain any spaces, such as:
C:\apps\Cmder
orC:\tools\Cmder
to avoid any conflicts with VS Code.If you for some reason really need to launch Cmder from a path with spaces, you might need to prepend a
^
symbol before each space, such thatC:\\Example Directory for Test\\Cmder
will becomeC:\\Example^ Directory^ for^ Test\\Cmder
in yoursettings.json
file.