集成终端Integrated Terminal

Azure Data StudioAzure Data Studio 中,可以打开一个集成终端,该终端最初从工作区的根目录启动。In Azure Data StudioAzure Data Studio, you can open an integrated terminal, initially starting at the root of your workspace. 可以便捷实现该操作,因为不必切换窗口或更改现有终端的状态,即可执行一个快速命令行任务。This can be 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:

  • 利用反撇号字符,使用 Ctrl+` 键盘快捷方式 。Use the Ctrl+` keyboard shortcut with the backtick character.
  • 使用“视图” | “集成终端”菜单命令 。Use the View | Integrated Terminal menu command.
  • 从命令面板 (Ctrl+Shift+P),使用“视图: 切换集成终端”命令 。From the Command Palette (Ctrl+Shift+P), use the View:Toggle Integrated Terminal command.

终端

备注

如果更喜欢在 Azure Data StudioAzure Data Studio 外部工作,仍然可以使用 Explorer 的“在命令提示符中打开”命令(在 Mac 或 Linux 中则为“在终端中打开”命令)打开外部 shell 。You can still open an external shell with the Explorer Open in Command Prompt command (Open in Terminal on Mac or Linux) if you prefer to work outside Azure Data StudioAzure Data Studio.

管理多个终端Managing Multiple Terminals

可以创建多个打开到不同位置的终端,并轻松在它们之间导航。You can create multiple terminals open to different locations and easily navigate between them. 可以通过点击 TERMINAL 面板右上角的加号图标或通过触发 Ctrl+Shift+` 命令来添加终端实例 。Terminal instances can be added by hitting the plus icon on the top-right of the TERMINAL panel or by triggering the Ctrl+Shift+` command. 这会在下拉列表中创建可用于切换的另一个条目。This creates another entry in the dropdown list that can be used to switch between them.

多个终端

按垃圾桶按钮删除终端实例。Remove terminal instances by pressing the trash can button.

提示

如果要广泛使用多个终端,可以为“键绑定”部分中列出的 focusNextfocusPreviouskill 命令添加键绑定,从而允许只使用键盘在他们之间导航。If you use multiple terminals extensively, you can add key bindings for the focusNext, focusPrevious and kill commands outlined in the Key Bindings section to allow navigation between them using only the keyboard.

配置Configuration

所使用的 shell 在 Linux 和 macOS 上默认为 $SHELL,在 Windows 10 上为 PowerShell,在早期版本的 Windows 上为 cmd.exe。The shell used defaults to $SHELL on Linux and macOS, PowerShell on Windows 10 and cmd.exe on earlier versions of Windows. 这些可在设置中通过设置 terminal.integrated.shell.* 手动覆盖。These can be overridden manually by setting terminal.integrated.shell.* in settings. 可以使用 terminal.integrated.shellArgs.* 设置将参数传递到 Linux 和 macOS上 的终端 shell。Arguments can be passed to the terminal shell on Linux and macOS using the terminal.integrated.shellArgs.* settings.

WindowsWindows

在 Windows 上正确配置 shell 需要找到正确的可执行文件并更新设置。Correctly configuring your shell on Windows is a matter of locating the right executable and updating the setting. 以下是常见 shell 可执行文件及其默认位置的列表:Below are a list of common shell executables and their default locations:

// 64-bit cmd if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe"
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"

备注

如果要作为集成终端使用,shell 可执行文件必须是控制台应用程序,以便能够重定向 stdin/stdout/stderrTo be used as an integrated terminal, the shell executable must be a console application so that stdin/stdout/stderr can be redirected.

提示

集成终端 shell 使用 Azure Data StudioAzure Data Studio 权限运行。The integrated terminal shell is running with the permissions of Azure Data StudioAzure Data Studio. 如果需要使用提升的(管理员)或不同的权限运行 shell 命令,可以在终端内使用平台实用程序,如 runas.exeIf 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.

Shell 参数Shell arguments

可以在 shell 启动时向其传递参数。You can pass arguments to the shell when it is launched.

例如,若要实现将 bash 运行为登录 shell(运行 .bash_profile),应传入 -l 参数(带双引号):For example, to enable running bash as a login shell (which runs .bash_profile), pass in the -l argument (with double quotes):

// Linux
"terminal.integrated.shellArgs.linux": ["-l"]

终端显示设置Terminal Display Settings

可以通过以下设置自定义集成终端字体和行高:You can customize the integrated terminal font and line height with the following settings:

  • terminal.integrated.fontFamily
  • terminal.integrated.fontSize
  • terminal.integrated.lineHeight

终端键绑定Terminal Key Bindings

“视图: 切换集成终端”命令会被绑定到“Ctrl +`”,以快速将该集成终端面板切入和切出视图 。The View: Toggle Integrated Terminal command is bound to Ctrl+` to quickly toggle the integrated terminal panel in and out of view.

下面是用于在集成终端内快速导航的键盘快捷方式:Below are the keyboard shortcuts to quickly navigate within the integrated terminal:

KeyKey CommandCommand
Ctrl+`Ctrl+` 显示集成终端Show integrated terminal
Ctrl+Shift+`Ctrl+Shift+` 创建新终端Create new terminal
Ctrl+UpCtrl+Up 向上滚动Scroll up
Ctrl+DownCtrl+Down 向下滚动Scroll down
Ctrl+PageUpCtrl+PageUp 向上滚动页面Scroll page up
Ctrl+PageDown Ctrl+PageDown 向下滚动页面Scroll page down
Ctrl+Home Ctrl+Home 滚动到顶部Scroll to top
Ctrl+End Ctrl+End 滚动到底部Scroll to bottom
Ctrl+K Ctrl+K 清除终端Clear the terminal

还有其他可用且可以绑定到首选键盘快捷方式的终端命令。Other terminal commands are available and can be bound to your preferred keyboard shortcuts.

它们分别是:They are:

  • workbench.action.terminal.focus设置用户帐户 :聚焦终端。workbench.action.terminal.focus: Focus the terminal. 这类似于切换,不同之处是如果终端可见,则聚焦终端而不是隐藏它。This is like toggle but focuses the terminal instead of hiding it, if it is visible.
  • workbench.action.terminal.focusNext设置用户帐户 :将焦点放在下一个终端实例上。workbench.action.terminal.focusNext: Focuses the next terminal instance.
  • workbench.action.terminal.focusPrevious设置用户帐户 :将焦点放在前一个终端实例上。workbench.action.terminal.focusPrevious: Focuses the previous terminal instance.
  • workbench.action.terminal.kill设置用户帐户 :删除当前终端实例。workbench.action.terminal.kill: Remove the current terminal instance.
  • workbench.action.terminal.runSelectedText设置用户帐户 :在终端实例中运行选定的文本。workbench.action.terminal.runSelectedText: Run the selected text in the terminal instance.
  • workbench.action.terminal.runActiveFile设置用户帐户 :在终端实例中运行活动文件。workbench.action.terminal.runActiveFile: Run the active file in the terminal instance.

运行所选文本Run Selected Text

要使用 runSelectedText 命令,请在编辑器中选择文本,然后通过命令面板 (Ctrl+Shift+P) 运行命令“终端: 在活动终端中运行所选文本” 。To use the runSelectedText command, select text in an editor and run the command Terminal: Run Selected Text in Active Terminal via the Command Palette (Ctrl+Shift+P). 终端随即尝试运行所选文本:The terminal attempts to run the selected text:

运行所选文本

如果在活动编辑器中未选择任何文本,则光标所在的行将在终端中运行。If no text is selected in the active editor, the line that the cursor is on is run in the terminal.

复制和粘贴Copy & Paste

复制和粘贴的键绑定遵循平台标准:The keybindings for copy and paste follow platform standards:

  • Linux:Ctrl+Shift+C 和 Ctrl+Shift+V Linux: Ctrl+Shift+C and Ctrl+Shift+V
  • Mac:Cmd+C 和 Cmd+V Mac: Cmd+C and Cmd+V
  • Windows:Ctrl+C 和 Ctrl+V Windows: Ctrl+C and Ctrl+V

查找Find

集成终端具有可通过 Ctrl+F 触发的基本查找功能 。The Integrated Terminal has basic find functionality that can be triggered with Ctrl+F.

如果想通过 Ctrl+F 转到 shell 而不是在 Linux 和 Windows 上启动“查找”小组件,需要删除键绑定,如下所示 :If you want Ctrl+F to go to the shell instead of launching the Find widget on Linux and Windows, you need to remove the keybinding like so:

{ "key": "ctrl+f", "command": "-workbench.action.terminal.focusFindWidget",
                      "when": "terminalFocus" },

重命名终端会话Rename terminal sessions

现在可以使用以下命令来重命名集成终端会话:“终端: 重命名”(workbench.action.terminal.rename) 。Integrated Terminal sessions can now be renamed using the Terminal: Rename (workbench.action.terminal.rename) command. 新名称显示在终端选择下拉列表中。The new name is displayed in the terminal selection drop-down.

强制通过终端传递键绑定Forcing key bindings to pass through the terminal

虽然焦点位于集成终端,但许多键绑定不会起作用,因为击键被传递给终端本身并由终端本身使用。While focus is in the integrated terminal, many key bindings won't work because the keystrokes are passed to and consumed by the terminal itself. 可通过 terminal.integrated.commandsToSkipShell 设置解决此情况。The terminal.integrated.commandsToSkipShell setting can be used to get around this. 它包含一组命令名称,其键绑定会跳过 shell 处理,转由 Azure Data StudioAzure Data Studio 键绑定系统来处理。It contains an array of command names whose key bindings skip processing by the shell and instead be processed by the Azure Data StudioAzure Data Studio key binding system. 默认情况下,除少数常用的键绑定外,其中还包括所有终端键绑定。By default this includes all terminal key bindings in addition to a select few commonly used key bindings.