ramian
ramian

Reputation: 81

How to integrate Cmder properly in VS Code?

I would like to integrate Cmder shell into my VS Code configuration.

I'm using VS Code 64bit on Windows, and I tried to modify my settings.json file as follows, to make Cmder work as the integrated terminal:

"terminal.integrated.shell.windows": "C:\\Program Files\\Cmder\\Cmder.exe",

I restarted my VS Code and tried to open the terminal.

At first, this error message box showed up:

Failed to copy ConEmu.xml file to backup location!
Restart Cmder as administrator.

So, I launched VS Code as administrator, which made the error message disappear; however, I noticed that VS Code opens Cmder in another separate window instead of in the terminal.

How can I run Cmder shell inside VS Code terminal?

P.S. Could this note in vs code documentation be the solution?

Tip: The integrated terminal shell is running with the permissions of VS Code. If you need to run a shell command with elevated (administrator) or different permissions, you can use platform utilities such as runas.exe within a terminal."

from: https://code.visualstudio.com/docs/editor/integrated-terminal

Upvotes: 4

Views: 10266

Answers (4)

Ian
Ian

Reputation: 31

This worked for me on June 22nd 2021; add these lines to the settings.json file in your user settings (for me « C:\Users\ianla\AppData\Roaming\Code\User\settings.json »):

"terminal.integrated.profiles.windows": {
    "cmder": {
      "path": "C:\\WINDOWS\\System32\\cmd.exe",
      "args": ["/K", "C:\\Users\\ianla\\cmder\\vendor\\bin\\vscode_init.cmd"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "cmder",

... of course, you'll need to change my « C:\Users\ianla\ » with your instalation "cmder" instalation path.

See here for more info

Upvotes: 3

emgf_co
emgf_co

Reputation: 373

The following is that worked for me (version of Cmder greater than 1.3.11):

  1. Paste \cmder directory into C:\tools

  2. Paste in .vscode\settings.json :

    "terminal.integrated.shell.windows": "cmd.exe",
    "terminal.integrated.env.windows": {
        "CMDER_ROOT": "C:\\tools\\cmder"
    },
    "terminal.integrated.shellArgs.windows": [
        "/k",
        "%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
    ],
    

.. and enjoy!

Upvotes: 2

testworks
testworks

Reputation: 396

Cmder 1.3.12 introduced a vscode_init.cmd script which allows VS Code tasks to work correctly with Cmder.

The documentation in VS Code, referred to in the answer above, is out of date if you're using a version of Cmder greater than 1.3.11.

The Cmder GitHub repository now has extensive documentation on how to achieve integration between Cmder and VS Code. At the time of writing this message, it is more accurate than the VS Code documentation.

Upvotes: 3

David Refoua
David Refoua

Reputation: 3617

There is a mistake in your configuration file, the following is not valid:

"terminal.integrated.shell.windows": "C:\\Program Files\\Cmder\\Cmder.exe"

You should not be calling Cmder.exe from the VS Code, instead, you should use init.bat (from the instructions below) to integrate Cmder in VS Code.

Your issue has been already explained here over the Cmder repository.


Making Cmder work in VS Code

  1. Make sure you're on the latest release of Cmder – download latest here

  2. Open the settings.json configuration file, by pressing Ctrl + , (Control-Comma) to access the preferences, then click on the Edit in settings.json link

  3. VS Code documentation explains the process in this link:
    Can I use Cmder's shell with the terminal on Windows?

    Yes, to use the Cmder shell in VS Code, you need to add the following settings to your settings.json file:

    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vendor\\init.bat"]
    
  4. BTW, You need to replace C:\\cmder with your own installation path.
    Tip: replace single backslashes (\) with double backslashes (\\).

  5. Make sure you read the notice at the official Cmder wiki:

    👉 Please note the use of cmd.exe instead of cmder.exe.

    Tip: refer to here on notes about handling spaces in your path.
    TL;DR: It's not recommended by the Cmder team, but you may use ^ character before spaces to handle the paths.

  6. You don't need to restart VS Code to make this work.
    Hit Ctrl + ` (Control-Tilde) to open Cmder in VS Code terminal!

You may refer to my answer here for a complete explanation of how this works.


Related

There are similar issues over the VS Code repo and here on Cmder repo as well.

Upvotes: 11

Related Questions