如何在 VisualStudio 代码中打开 shell 命令提示符?

在使用 VisualStudio 代码时,如何运行命令行程序,如 Choco (Chocolatey)命令?我是否需要在 VS Code 之外运行一个单独的命令行(CMDexe) ,或者在 Code 中是否有一个热键/窗口可以运行这些命令?

我看到了“命令调色板”,但是并不完全清楚在这个调色板中运行的是什么命令引擎。

121575 次浏览

Use CMD+Shift+C or CTRL+Shift+C but it will only open a new outside editor standard bash console.

I hope they will implement an integrated console.

As MCBL wrote, there is no integrated console. You can vote for this feature here: UserVoice - Integrated terminal <-- dead link.

3rd party Edit

Uservoice is no longer used and the link above is dead. The feature request for an integrated terminal might be this one.

Since the Debug Console does not support programs that need to read input from the console, you can enable an external, native console by setting the attribute externalConsole to true in your launch configuration. lauch.json just write: "externalConsole" : true

For integrated terminal use Ctrl+`

From the release notes:

With the May release, we are rolling out the initial version of an integrated terminal. You can open the terminal using Ctrl+`, from the View | Toggle Integrated Terminal menu, or from the View > Toggle Integrated Terminal command in the Command Palette.

https://web.archive.org/web/20160616204248/http://code.visualstudio.com/updates/#_workbench (the 1.2.0 May release in 2016)

@brady321's answer is only for US keyboards:

Note: The following keys are rendered assuming a standard US keyboard layout.(https://code.visualstudio.com/Docs/customization/keybindings)

For instance, UK keyboards use Ctrl+':

You can find your shortcut in File > Preferences > Keyboard Shortcuts searching for workbench.action.terminal.toggleTerminal. If you're not using a US keyboard, it will show you the equivalent shortcut using your keyboard layout:

enter image description here

To check what the shortcut to open a native console looks like, try to find workbench.action.terminal.openNativeConsole in the shortcuts file.

More information about integrated terminal at: https://code.visualstudio.com/docs/editor/integrated-terminal

I used custom shortcut. Add below keybind to the keybinds.json:

[
{
"key": "ctrl+,",
"command": "workbench.action.terminal.toggleTerminal"
}
]

To open keybinds.json

CTRL + SHIFT + P then type Keyboard and click to Open Keyboard Shortcuts

Can open it with this menu options: View > Integrated Terminal

Default keyboard shortcut for integrated terminal is Ctrl+`

In vscode you can use multiple integrated terminals.
If you want open another one use Ctrl+Shift+`

vscode keys shortcuts are rendered assuming a standard US keyboard layout. If you use a different keyboard layout, please read how can see the representation in your current keyboard. It's easy, open this menu options: File > Preferences > Keyboard Shortcuts and on the Default Keyboard Shortcut search the command workbench.action.terminal.toggleTerminal then point you mouse to info icon and can see the combination. For me is Ctrl+ñ because I'm using Spanish keyboard layout.

enter image description here

Also it's cool create an personal shortcuts to toggle into terminals. Open this menu options: File > Preferences > Keyboard Shortcuts and on the keybinding.json tab put this:

[
{
"key": "ctrl+pageup",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},{
"key": "ctrl+pagedown",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
}
]

Now when the cursor are focus on terminal, and have more than one terminal, you can navigate through every one with the combinations Ctrl+Page Down for previous terminal and Ctrl+Page Up for next terminal.

Tip: If you are focus on the editor, the same keyboard shortcuts can be used to navigate through tabs.

In the contrary you may also run a terminal inside your visual studio code tool by simply doing the following:

Go to " View > Integrated Terminal " or use the shortcut key " Ctrl + ' "

I believe this is available on later versions of visual studio code. I could do this on version 1.7.0-insider.

Ctrl+ `

Integrated Terminal In Visual Studio Code, you can open an integrated terminal, initially starting at the root of your workspace. This can be very convenient as you don't have to switch windows or alter the state of an existing terminal to perform a quick command line task.

To open the terminal:

I am using vsCode 1.9.1. there are 2 ways as I know

  1. You can easily open it by hitting Ctrl + ` key.
  2. Go to View->Integrated Terminal like below image

terminal for vscode

On my UK MacBook, when I look in my keyboard shortcuts for VS Code (Code > Preferences > Keyboard Shortcuts), Toggle Integrated Terminal has the keybinding Crtl+`.

However, the shortcut works on Ctrl+§, which is the key on my MacBook that is the same place as the ` on a UK Windows keyboard.

You can take the text editor of the Microsoft, but you can't take the etc, etc.

The best way to run command line programs is to use the terminal window provided inside VS Code. This way tou will not switch any apps. But to make switching between terminal and other windows I recommend the following :

  1. To open up a terminal - Ctrl + `
  2. To open up second terminal - when you are running a node script in the first terminal and it is blocked and you need to run second script at the same time - Ctrl + Shift + `
  3. To focus/switch back on terminal without reopening :
    1. Press F1 and then type keyboard shortcuts
    2. Find workbench.action.terminal.focus and set it to Ctrl + \ - this slash is usually located right next to your right Ctrl key. This makes switching between code and terminal very easy because Ctrl + ` and Ctrl + \ are invoked with your right hand and index finger.

test with the Ctrl + J keys in ubuntu

Switch the Integrated Terminal to CMD

  1. Open the Integrated Terminal: Ctrl + `
  2. If a Bash terminal is opened while you want a Command Prompt (cmd), simply run the command: cmd, in the terminal to switch it to Command Prompt.

enter image description here

Test this, This works for me

Ctrl + ñ

Ctrl + `

ctrl + j

Also for MAC its Ctrl+Shift+.

I prefer you to change to a custom one.
Open up Command Palette by Command+Shift+P.

Type 'Keyboard Shortcuts...' - Select Preferences: Open Keyboard Shortcuts

enter image description here.
See Terminal: Create New Integrated Terminal option there. Double-tap it to change it to a custom one.

enter image description here. enter image description here

Go to File > Preferences > Keyboard Shortcuts or use shortcut Ctrl+K Ctrl+S.

Type to search in keybindings : workbench.action.terminal.new.

Double click on Keybinding and add the shortcut you want (ABC0+T is unused in default config).

For mac Cmd + j
For win Ctrl + j

For me:

ctrl + shift + `

Seems to have done the trick with the default VSCode settings. If you hover your cursor over the +-button to add a new terminal, you can actually see what you need to press for the shortcut.