How to use Cmder in Visual Studio Code?
Asked Answered
S

14

51

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?

Stethoscope answered 18/8, 2017 at 22:34 Comment(4)
Fix here: #47268352Brigette
@Adson, thanks? I've already posted a solution to my question, and the answer you linked didn't exist until 5 months after I asked my question.Stethoscope
Surrounding the whole path in quotes is close to but not quite the correct syntax for it. The qoutation marks should surround the specific block of text containing spaces, i.e "C:\\\"Program Files (x86)\"\\Cmder\\vendor\\init.bat". I know the issue is already resolved in other ways but I hope this tidbit is useful regardless.Sulphate
The official Cmder guide here: github.com/cmderdev/cmder/wiki/Seamless-VS-Code-IntegrationEssen
S
75

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:

Image of Cmder being successfully loaded in the VS Code integrated terminal.

Stethoscope answered 18/8, 2017 at 22:34 Comment(4)
how are you getting the colors and look in general of cmder in vscode? I follow your step and I did got cmder to work in the console but it is all whiteElburt
@David Martinez, try changing the color scheme to a darker one. See this article: code.visualstudio.com/docs/getstarted/themesStethoscope
if you guys cannot find C:/Windows/Sysnative folder try this: C:\\WINDOWS\\SysWOW64\\cmd.exeRoderickroderigo
There is an official documentation about Cmder integration in VS Code: github.com/cmderdev/cmder/wiki/Seamless-VS-Code-IntegrationInterpretive
M
24

another solution is you can set your cmder location into new path

image was from nikrolls when giving the solution

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

Militarism answered 25/11, 2017 at 0:23 Comment(1)
There are also some other benefits as well to set the environment variable: github.com/cmderdev/cmder/wiki/Setting-up-Environment-Variables#should-i-use-this-methodEssen
C
21

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",
Caravan answered 29/5, 2021 at 0:3 Comment(3)
Works fine, but is there any way to remove the initial logging when opening a new terminal?Tubuliflorous
@Tubuliflorous You can update %CMDER_ROOT%/bin/vscode_init_args.cmd and comment the last few linesAntitoxic
Worked for me in 2022. Remember to replace C:\\ with whatever your actual path to cmdr is if its not in the root directory.Infirmary
E
11

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 or C:\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 that C:\\Example Directory for Test\\Cmder will become C:\\Example^ Directory^ for^ Test\\Cmder in your settings.json file.

Essen answered 26/1, 2019 at 1:1 Comment(1)
According to my experiences, you have to escape the parentheses as well as spaces. Here's how C:\Program Files (x86)\Cmder works for me: "C:\\Program^ Files^ ^(x86^)\\Cmder".Shcherbakov
C
3

https://github.com/cmderdev/cmder/wiki/Seamless-VS-Code-Integration

 "terminal.integrated.shell.windows": "cmd.exe",

  "terminal.integrated.env.windows": {
  "CMDER_ROOT": "[cmder_root]"
  },
  "terminal.integrated.shellArgs.windows": [
    "/k [cmder_root]\\vendor\\init.bat"
  ],

Substitute both [cmder_root] with your Cmder installation directory.

second solution

"terminal.integrated.shell.windows": "C:\\Program Files\\cmder\\vendor\\git-for-windows\\bin\\bash.exe",
Cloy answered 8/5, 2019 at 7:38 Comment(0)
N
3

A very easy solution (source):

Create a file in the root of your cmder folder vscode.bat with the following code.

@echo off
SET CMDER_ROOT=C:\cmder <--your path to cmder
"%CMDER_ROOT%\vendor\init.bat"

Then in your vscode settings add the following to your settings.json:

"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
 "terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vscode.bat"] <-- your path

You can also easily switch between cmd and cmder by commenting in and out "terminal.integrated.shellArgs.windows".

Nebulosity answered 5/7, 2019 at 10:27 Comment(0)
S
3

Cmder with VSCode 2021

  • Step 1: Download Cmder
  • Step 2: Save Cmder to C:\cmder
  • Step 3: Open Settings.json in VSCode
  • Step 4: Create VSCode Integrated Terminal Settings
"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",
  • Step 5: restart VSCode
  • Step 6: Happy coding! 😁
Supposed answered 17/9, 2021 at 14:39 Comment(0)
S
2

It's work for me. My Cmder root directory: D:\soft\cmder, attention yours!

"terminal.integrated.env.windows": {"CMDER_ROOT": "D:\\soft\\cmder"},
"terminal.integrated.shellArgs.windows": ["/k D:\\soft\\cmder\\vendor\\init.bat"],

Add it in your VSCode settings. enjoy it!

Salad answered 12/3, 2018 at 5:46 Comment(1)
The previous solutions did not work for me, with an error message in the terminal about not being able to access "C:\Config". This solution, however, did work for me.Cordova
D
0

The best solution I found: Fast and easy.

"terminal.external.windowsExec": "C:\\Utils\\Cmder\\Cmder.exe",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe"
"terminal.integrated.shellArgs.windows" : ["/K","C:\\Utils\\cmder\\vendor\\init.bat"],
Demisemiquaver answered 29/7, 2019 at 14:0 Comment(0)
F
0

This solution its good on open terminal but breaks cmd calls launched via plugins with arguments like npm build - lint, etc.

A solution to fix it is to create a custom init.bat that wraps these calls and reference it on sellArgs.

settings.json

"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.shellArgs.windows": [
    "/K C:\\SoftDev\\App\\Cmder\\vendor\\vstudio.bat"
],

C:\SoftDev\App\cmder\vendor\vstudio.bat

@echo off
if "%1" == "" (
    C:\SoftDev\App\cmder\vendor\init.bat
) else (
    cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
    exit
)
Fearnought answered 9/8, 2019 at 10:12 Comment(0)
R
0

@Ari Maulana works like a charm...

add "CMDER_ROOT" on variables 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"
]
Retreat answered 31/3, 2020 at 23:53 Comment(0)
C
0

There are two Extensions to include Cmder into VS Code but none of them work in Win 7 (I know is quite old) anyway while some of the answer here helped didn't work for my case.

The locations details:

cmd.exe = C:\Windows\System32\cmd.exe
I am using a portable version of Cmder in C:\cmder\Cmder.exe
init.bat = C:\cmder\vendor\init.bat
setting.json = C:\Users\Admin\AppData\Roaming\Code\User\settings.json

This is my settings.json

{
    "window.zoomLevel": 0,
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\cmder\\vendor\\init.bat"
    ]
}

And the screenshot where it's properly working

Cmder integrated into VS Code

Note: That I didn't need to add Cmder into the Environment Path

Ceratoid answered 20/6, 2020 at 7:39 Comment(0)
C
0

In visual studio press ctrl + p

Write / go to settings.json

Paste this inside

"terminal.integrated.profiles.windows": {
  "Cmder": {
    "path": "${env:windir}\\System32\\cmd.exe",
    "args": ["/k", "C:\\cmder\\vendor\\git-for-windows\\bin\\bash.exe"]
  }
},
"terminal.integrated.defaultProfile.windows": "Cmder",

Make sure that the "args" is the directory where you placed cmder in your machine.

Countershaft answered 18/11, 2021 at 15:21 Comment(0)
E
-1

The command line interpreter in Windows has some issues with spaces in the path, such as C:\Program Files\Cmder or C:\Program Files (x86)\Cmder. instead, create a new folder like "apps" and use path has no space like c:\apps

Enter answered 20/2, 2020 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.