I'm trying to use Cmder in VS Code for PowerShell instead of powershell.exe. I followed the official instructions (here) on the cmder GitHub. Now, when I restart VS Code a terminal will be launched. Looks like this:
It's name is 'powershell' and it looks like Cmder but doesn't behave like it.
Perhaps I'm expecting something that is not designed to work but I was expecting 'CTRL+ Backspace' to delete words to the left. Instead I'm getting '^W':
Moreover, as soon as I open a .ps1 file a new terminal gets launched which is named 'PowerShell Integrated Console':
The behaviour of this terminal is the same as the 'powershell' one.
Here's my settings related to the integrated terminal and PowerShell in the settings.json:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows": [
"-ExecutionPolicy",
"Bypass",
"-NoLogo",
"-NoProfile",
"-NoExit",
"-Command",
". 'C:\\Users\\fhe\\[REMOVED]\\Apps\\cmder_mini\\vendor\\profile.ps1'"
],
"terminal.integrated.rendererType": "auto",
"terminal.integrated.scrollback": 10000,
"powershell.scriptAnalysis.enable": true,
"powershell.integratedConsole.focusConsoleOnExecute": false,
"powershell.enableProfileLoading": true,
I notice that if I change it back to what the official guide suggests under the 'Run Cmder as the VS Code terminal' (here) I will get the expected behaviour when using CTRL+Backspace.
So my questions are:
Is Cmder integration in VS Code designed to provide the CTRL+Backspace functionality for PowerShell?
If so, what might I have configured incorrectly?
Thanks.
Related
I would like to have the Microsoft VS C++ compiler cl available in VisualStudio Code.
I have Visual Studio Build Tools installed and can call cl from the Developer Command prompt.
The default way recommended by Microsoft to get VS Code to use the cl compiler is to call VS Code from the Developer Command prompt.
I would like to do it differently, with a terminal that I can call from VS Code and make it the default terminal if needed.
In Windows Terminal, I get the automatically generated Developer Command prompt entry with the command line:
cmd.exe /k "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64`
or
powershell.exe -NoExit -Command "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell 0d0637f3 -SkipAutomaticLocation -DevCmdArguments """-arch=x64 -host_arch=x64"""}"
If I paste this line into an existing vscode terminal, it works and I can use the cl compiler. But I can't manage to get it into an integrated terminal in settings.json.
This is what I tried in the settings.json:
"Developer Command Prompt for VS 2022": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe /k \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" -arch=x64 -host_arch=x64",
"${env:windir}\\System32\\cmd.exe /k \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" -arch=x64 -host_arch=x64"
],
"overrideName": true,
"args": [],
"icon": "terminal-cmd"
},
Since VScode is pretty smart, it recognizes that this won't work and doesn't even list it as an entry within the available terminals.
Furthermore, i have absolutely no idea what to do with the commandline given for PowerShell, notably the three doublequotes after Import-Module and how to handle them.
Try the following to load VsDevCmd.bat in cmd.exe from the VSCode integrated terminal.
For running it through PowerShell, you should be able to just replace the path with PowerShell, and alter the arguments to match accordingly (/k would become -NoExit, etc).
"VsDevCmd (2022)": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/k",
// Path below assumes a VS2022 Community install;
// update as appropriate if your IDE installation path
// is different, or if using the standalone build tools
"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/Tools/VsDevCmd.bat",
"-arch=x64",
"-host_arch=x64"
],
"overrideName": true,
"icon": "terminal-cmd"
},
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!
I was able to setup VSCode so that I use Cmder on top of powershell.exe.
I was hoping that this would allow me to use common keyboard shortcuts such as Ctrl+Backspace to remove words faster. Unfortunately, it only outputs '^W' each time I hit that shortcut. In the standard cmd.exe or Cmder outside of VSCode this shortcut works.
Any idea why that is? I was thinking that that I'm expecting form this might not even be something that's supposed to work.
Thanks!
Here're my settings for reference:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows": [
"-ExecutionPolicy",
"Bypass",
"-NoLogo",
"-NoProfile",
"-NoExit",
"-Command",
". 'C:\\Users\\..\\..\\Apps\\cmder_mini\\vendor\\profile.ps1'"
],
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"]
With Visual Studio Code (not the traditional Visual Studio IDEs), can you run PowerShell in the Command Palette? I ask because I commonly use it in the full IDE.
I have not seen PowerShell mentioned in the documentation, other than for basic syntax highlighting. I have tried it with no success. Is it unsupported, or is it an optional feature I can configure somehow?
Note: to those voting up the PowerGUI answer, it is not correct as it references the wrong edition of Visual Studio for this question. It is helpful if you are using the full IDE, but not the new editor named: Code.
This was the first problem I wanted to solve in VSCode. I did not find a way to
type PowerShell commands but I have found a way to create and run PowerShell tasks.
In the command palette type and choose Tasks: Configure Task Runner. It will
show you a json file configured for the default task runner.
I replaced the content with this
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"-NoProfile",
"Invoke-Build.ps1"
],
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "Test",
"isTestCommand": true,
"showOutput": "always"
},
{
"taskName": "Build, Test",
"showOutput": "always"
}
]
}
As a result in the command palette I can choose and run my predefined tasks (Build, Test, and combined Build, Test). I can add other tasks and probably bind them to some hotkeys. This is not exactly what I would like to have in VSCode for PowerShell but for the preview it is at least something.
P.S. This just my first experiment that somewhat worked. It is not perfect, more likely. There are many configuration parameters for this json file that I have not tried yet.
With version 0.10.1 of Visual Studio Code, you can run and debug PowerShell. Here is a sample launch.json that I use:
{
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell",
"type": "PowerShell",
"program": "MyScript.ps1",
"args": "-Verbose"
}
]
}
Unfortunately, I cannot get the args to work (for more details, see: https://github.com/PowerShell/vscode-powershell/issues/24). Another problem I have is that Read-Host does not work with VS Code (for more details, see: https://github.com/PowerShell/vscode-powershell/issues/29). Definitely some rough edges.
Here's how you can configure the Powershell task to execute the currently opened .ps1 file without any Invoke-Build dependency:
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"${file}"
],
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "Test",
"isTestCommand": true,
"showOutput": "always"
},
{
"taskName": "Build, Test",
"showOutput": "always"
}
]
}
Note: This is just a slight modification of Roman's answer (My edit to his answer was rejected).
Open the Debug view, in the View Bar select Debug from the View menu or press Ctrl + Shift + D.
In the Launch Configuration dropdown (shown in the following screenshot), select Add Configuration...
The launch.json configuration will open in the editor, type PowerShell and select the debug configurations you want, as shown in the following screenshot.
Save the launch.json file and select the debug configuration you want from the Launch Configuration dropdown:
Now you can debug PowerShell scripts through VSCode.
The Scripting Guys wrote a comprehensive 2 part blog post on this topic, like everything else they write, it's well worth a read if you're new to VSCode and PowerShell.
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/
EDIT: I am aware that this question is several years old, but I came across it before I found any up to date information on how to set up PowerShell debugging in VSCode
As of version 0.10.3 there is now a PowerShell extension written by Microsoft that will enable writing PowerShell with IntelliSense and highlighting in Visual Studio Code
http://blogs.msdn.com/b/powershell/archive/2015/11/17/announcing-windows-powershell-for-visual-studio-code-and-more.aspx
At least in V1.4 (July 2016) this has been made a lot simpler.
The relevant documentation can be found here:
https://code.visualstudio.com/docs/editor/integrated-terminal
Essentially all you're doing is adding an entry to the settings.json file for User Settings.
Adding the following value:
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows":"C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
IMG: Shows the User Settings settings.json file and the successful Integrated Console showing the PowerShell prompt:
An "Integrated Terminal" is now integrated into Visual Studio Code. This is a PowerShell Terminal in Windows. (Likely BASH in Linux / MacOS). The terminal appears in a panel at the bottom of the code editor, not in the Command Pallete.
Keyboard Shortcut to open Terminal: CTRL + `
Sources:
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
https://code.visualstudio.com/docs/getstarted/keybindings
I confirmed in version 1.19.2. Not sure when the feature was first integrated.
There is a much easier way to run PowerShell, no configuration needed:
Install the Code Runner Extension
Open the PowerShell code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will run and the output will be shown in the Output Window.
Besides, you could select part of the PowerShell code and run the code snippet. Very convenient!
PowerGUI tool provides a nice interface to Visual Studio. The goal of this extension is to bring PowerShell development into Visual Studio.
Here is how it looks -
Along with IntelliSense, the PowerGUI Visual Studio Extension provides the following features and more to make it easier to work with PowerShell.
PowerShell file and project types: You can create/edit PowerShell code files and assemble them into projects with more than one file.
PowerShell code snippets: The code snippet feature can be used for PowerShell code.
PowerShell console window: This feature provides the PowerShell console environment within Visual Studio IDE. This allows you to run commands or view output of scripts. Figure B shows the console window opened in the IDE.
PowerShell debugging: This feature is why I installed the extension; it provides a way to debug scripts within Visual Studio. It's a straight-forward way to locate syntax or logical problems in a script.
Syntax highlighting and script analysis: These are more Visual Studio features made available to PowerShell development.
In order to install the PowerGUI Visual Studio Extension, PowerGUI must be installed, with the caveat that the correct version of each product is installed.
Download Here
It also provides Debugging facility which is the best part I like as a developer.
Thanks!