How to integrate Cmder properly in VS Code? - visual-studio-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

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
Make sure you're on the latest release of Cmder – download latest here
Open the settings.json configuration file, by pressing Ctrl + , (Control-Comma) to access the preferences, then click on the Edit in settings.json link
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"]
BTW, You need to replace C:\\cmder with your own installation path.
Tip: replace single backslashes (\) with double backslashes (\\).
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.
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.

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.

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

The following is that worked for me (version of Cmder greater than 1.3.11):
Paste \cmder directory into C:\tools
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!

Related

VS Code Not Running Anything - No such file or directory

My VS Code
My VSCode for Mac won't run even simple Python commands. For more context my Python Terminal execute in file dir setting is turned on. I don't know what the problem is, the play button or right clicking and selecting run code also doesn't do anything.
I've already ensured I have the proper VSCode installed for Mac. Please help :(
try to edit your settings.json file like this :
"terminal.explorerKind": "external",
"terminal.integrated.defaultProfile.windows": "Command Prompt"
learn more about using python in VS Code

Visual Studio Code terminal error: The filename, directory name, or volume label syntax is incorrect

I have this issue in microsoft visual studio code, whenever I open the terminal the first message I get is The filename, directory name, or volume label syntax is incorrect. The terminal works fine.. just it bugs me to see see this error message whenever I open the terminal.. how do I fix it?
I Installed Cmder as my default visual studio code terminal, maybe there is something related to this error?
thanks in advance
I am not sure how you have installed cmder as the integrated terminal in vscode but in settings.json you could try pointing the terminal.integrated.shell.windows to cmd.exe and the terminal.integrated.shellArgs.windows to what makes cmd.exe be (act like) cmder which is cmder's init.bat file. So in your vscode settings.json add or modify the below lines to point to your cmd.exe and cmder init.bat respectivley.
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [ "/k", "C:\\cmder\\vendor\\init.bat"],
I got the same problum but it got fixed by following this steps
go to setting and search json
click on launch -(Edit in setting.json)
now replace the line "terminal.integrated.shell.windows":(path as showing) line to
"terminal.integrated.shell.windows": "C:\Windows\System32\cmd.exe",
"terminal.integrated.shellArgs.windows": [ "/k", "C:\cmder\vendor\init.bat"],
save the program. Done!

Visual Studio Code - Ctrl+Backspace not working in Integrated Terminal

In the terminal (PowerShell) in Visual Studio Code, I'm trying to hit Ctrl+Backspace to delete last word, but it just adds ^W to end of the line, any ideas how to fix this? It works fine outside Visual Studio Code in PowerShell.
ctrl+backspace is somehow mapped to ctrl+w in vscode integrated terminal (possibly a bug) and now we need to set ctrl+w binding to delete the word explicitly. weird right?
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
Note that this'll work for the current terminal session only.
To make this behaviour persistent, you can set it in profile Microsoft.PowerShell_profile.ps1 file. Create the file if it doesn't exist in your powershell version folder.
C:\Program Files\PowerShell\6\Microsoft.PowerShell_profile.ps1
write at the top
if ($env:TERM_PROGRAM -eq "vscode") {
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
}
See more: Power up your PowerShell
Keybinding references:
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/Get-PSReadLineKeyHandler?view=powershell-5.0
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/set-psreadlinekeyhandler?view=powershell-5.0
Based on the latest comment https://github.com/microsoft/vscode/issues/68167 I have modified JerryGoyal's answer so we don't have to modify bindings:
Put the following at the top of your Microsoft.PowerShell_profile.ps1 config file (type $profile in the terminal to find it, you might have to create one if it doesn't exist already)
if ($env:TERM_PROGRAM -eq "vscode") {
Set-PSReadLineOption -EditMode Emacs
}
This works for me (vscode 1.43)
It was showing ^W when I pressed Ctrl+Backspace.
Just run this command in the vscode console
Set-PSReadLineOption -EditMode Emacs
NOW IT WORKS!
Looks like an issue that is being tracked: see workbench.action.terminal.deleteWordLeft Doesn't Work, Outputs ^W.
Works fine for me in git bash terminal but not powershell as of vscode 1.36.
vscode v1.45 made some changes to these terminal commands, like deleteWordLeft. Does Ctrl+Backspace work better for you now?
See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#removal-of-several-prompt-related-commands
VSCode 1.48 (July2020) might help.
Issue 98404 does allow ctrl+backspace to delete entire word in cmd.exe, which could work for a powershell session too.
See PR 98494:
Before (when it was not working):
After (working):
Check you keybindings in your settings to be sure it is still set.
I have had some oddities with keybindings getting removed / changed when adding a new extension or an update. You may just need to add it back.
Key Bindings for Visual Studio Code
Of course VSCode and PowerShell are two different environments. If you split your terminal window (I do this all the time for my own work use case), you will end up with the VSChost and the standard consolehost and you'll see that though you are in VSCode, they behave differently.
If you have not done so, you may want to customize you VSCode profile which is what the integrated console will read, where as the consolehost will read your PowerShell console profile not you ISE profile.
To add to JerryGoyal answer:
If you have difficulties finding profile folder and/or making it works. Here's what helped me.
I created folder c:\Users\YOUR_USER_NAME\Documents\WindowsPowerShell\
Put Microsoft.PowerShell_profile.ps1 there
Powershell than tells you about security problems. You have to allow this by running powershell as admin.
Than type Set-ExecutionPolicy RemoteSigned.
Answer Y(yes). This is obviously at your own risk!
Add this to keybindings.json in vs code
{
"key": "ctrl+backspace",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": { "text": "\u0017" }
},

VSCode + Cmder integration - strange issue

could you tell me why while I integrate the vscode and cmder, like that:
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.shellArgs.windows": ["/k", "%CMDER_ROOT%\\vendor\\init.bat"]
and use mini_cmder version, everything is working fine. But if I do it the same with full version of cmder, the "Open in terminal" option from contextual menu doesen't work. Anybody know how to resolve that?
Best Regards,
crova
Yes, to use the Cmder shell in VS Code, you need to create a vscode.bat file in your cmder path with the following contents:
#echo off
SET CurrentWorkingDirectory=%CD%
SET CMDER_ROOT=C:\cmder (your path to cmder)
CALL "%CMDER_ROOT%\vendor\init.bat"
CD /D %CurrentWorkingDirectory%
then in your VS Code user settings, add the following to your settings.json file:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vscode.bat"]

In Visual Studio Code, how do you inject clink into the integrated terminal?

I was using clink with ConEmu for various node related tasks on windows, but now I'm trying Visual Studio code.
How do I inject clink into Visual Studio Code's integrated terminal, so that I can get real command history persistence between sessions, incremental history search, etc.?
With ConEmu I could inject clink by dropping the clink folder into a specified pickup directory.
I've tried using the path to the included clink bat file, and the clink exe in the VS Code setting terminal.integrated.shell.windows but these spawn and then close the command shell immediately.
Thanks!
I discovered that you can pass arguments to the integrated shell in Visual Studio Code. Combined with the cmd.exe /K option which Carries out the command specified by string but remains, clink can be injected.
In VS Code, go to File > Preferences > Settings or use Ctrl , and add the settings:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "C:\\path\\to\\clink\\clink_x64.exe inject"]
This is the equivalent of opening a command prompt in Windows, and running clink_x64 inject.
It is not answer for your question, but there is another trick to see cmder and text editor in one window. You can open your text editor as another tab in cmder, which I described here:
https://medium.com/#WMorkowski/protip-integrating-cmder-with-text-editor-7f08a6e76de7
from article:
Run your cmder.
Go to ‘Settings -> Startup -> Environment’
Type: set EDITOR_PATH=C:\Program Files (x86)\Microsoft VS Code\Code.exe alias editor="%EDITOR_PATH%" $1 -new_console:s50V Where
in the first line you should type path to your text editor (I was
testing it on Visual Studio Code and Sublime, but it should work with
other editors).
Save your settings
Type ‘editor’ command in command line.
Whoa! We almost finished. But in most cases you don’t want console tab
to be attached to the top of the window. You should close console tab,
and open it again, paying attention to check “New console split to
bottom” checkbox and choose the right console type. Now when you
finally set everything up, you should go to ‘Settings -> Startup’, and
check “Auto save/restore opened tabs” checkbox to save our new
workflow. Now every time you run cmder, your tabs setup will be
restored.
Expanding on my comment:
Open settings.json with:
File > Open > %APPDATA%\Code\User\settings.json
And assuming you installed clink with the magic of chocolatey:
choco install clink-maintained
Then your clink_x64.exe lives here:
C:\Program Files (x86)\clink\clink_x64.exe
And the lines you add to settings.json look like:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/K",
"C:\\Program Files (x86)\\clink\\clink_x64.exe",
"inject",
"--profile",
"~\\clink"
],
Note the addition of --profile ... this allows the history to be persistent between vscode sessions.