Windows 终端中的自定义键绑定Custom key bindings in Windows Terminal

可以在 Windows 终端中创建自定义键绑定(键盘快捷方式),从而控制使用键盘与终端进行交互的方式。You can create custom key bindings (keyboard shortcuts) inside Windows Terminal that give you control of how you interact with the terminal using your keyboard.

键绑定格式Key binding formats

可以采用以下格式构造键绑定:Key bindings can be structured in the following formats:

不带参数的命令Commands without arguments

{ "command": "commandName", "keys": "modifiers+key" }

例如,此默认设置使用快捷键 alt+f4 关闭终端窗口:For example, this default setting uses the shortcut key alt+f4 to close the terminal window:

{ "command": "closeWindow", "keys": "alt+f4" }

带参数的命令Commands with arguments

{ "command": { "action": "commandName", "argument": "value" }, "keys": "modifiers+key" }

例如,此默认设置使用快捷键 ctrl+shift+1 在终端中打开一个新选项卡,具体取决于下拉菜单中列出的第一个配置文件(通常这将打开 PowerShell 配置文件):For example, this default setting uses the shortcut key ctrl+shift+1 to open a new tab in the terminal based on whichever profile is listed first in your dropdown menu (typically this will open the PowerShell profile):

{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+shift+1" }


键绑定属性Key binding properties

可以使用以下属性构造键绑定。Key bindings can be constructed using the following properties.

命令Command

这是在按下关联的键时执行的命令。This is the command executed when the associated keys are pressed.

属性名称: commandProperty name: command

必要性: 必需Necessity: Required

接受: 字符串Accepts: String

Keys

这会定义用于调用命令的键组合。This defines the key combinations used to call the command. 一个键可以拥有任意数量的修改键。Keys can have any number of modifiers with one key. 下面列出了接受的修改键和键。Accepted modifiers and keys are listed below.

属性名称: keysProperty name: keys

必要性: 必需Necessity: Required

接受: 字符串或 array[string]Accepts: String or array[string]

操作Action

这会向某些命令添加其他功能。This adds additional functionality to certain commands.

属性名称: actionProperty name: action

必要性: 可选Necessity: Optional

接受: 字符串Accepts: String



接受的修改键和键Accepted modifiers and keys

修改键Modifiers

ctrl+shift+alt+ctrl+, shift+, alt+

修改键Modifier keys

类型Type Keys
功能键和字母数字键Function and alphanumeric keys f1-f24a-z0-9f1-f24, a-z, 0-9
符号Symbols `-=[]\;',./`, -, =, [, ], \, ;, ', ,, ., /
箭头键Arrow keys downleftrightuppagedownpageuppgdnpgupendhomeplusdown, left, right, up, pagedown, pageup, pgdn, pgup, end, home, plus
操作键Action keys tabenterescescapespacebackspacedeleteinserttab, enter, esc, escape, space, backspace, delete, insert
数字键Numpad keys numpad_0-numpad_9numpad0-numpad9numpad_addnumpad_plusnumpad_decimalnumpad_periodnumpad_dividenumpad_minusnumpad_subtractnumpad_multiplynumpad_0-numpad_9, numpad0-numpad9, numpad_add, numpad_plus, numpad_decimal, numpad_period, numpad_divide, numpad_minus, numpad_subtract, numpad_multiply


应用程序级命令Application-level commands

关闭窗口Close window

这会关闭当前窗口和其中的所有选项卡。This closes the current window and all tabs within it. 如果 confirmCloseAllTabs 设置为 true,则会出现一个确认对话框,以确认你希望关闭所有选项卡。If confirmCloseAllTabs is set to true, a confirmation dialog will appear to ensure you'd like to close all your tabs. 有关此设置的详细信息,请参阅全局设置页More information on this setting can be found on the Global settings page.

命令名称: closeWindowCommand name: closeWindow

默认绑定:Default binding:

{ "command": "closeWindow", "keys": "alt+f4" }

Windows 终端确认关闭所有选项卡

查找Find

这将打开搜索对话框。This opens the search dialog box. 有关搜索的详细信息,请参阅搜索页More information on search can be found on the Search page.

命令名称: findCommand name: find

默认绑定:Default binding:

{ "command": "find", "keys": "ctrl+shift+f" }

打开下拉菜单Open the dropdown

这将打开下拉菜单。This opens the dropdown menu.

命令名称: openNewTabDropdownCommand name: openNewTabDropdown

默认绑定:Default binding:

{ "command": "openNewTabDropdown", "keys": "ctrl+shift+space" }

打开设置文件Open settings files

这会打开默认或自定义设置文件。This opens either the default or custom settings files. 如果没有 target 字段,这会打开 settings.json 文件。Without the target field, this will open the settings.json file.

命令名称: openSettingsCommand name: openSettings

默认绑定:Default binding:

{ "command": "openSettings", "keys": "ctrl+," },
{ "command": { "action": "openSettings", "target": "defaultsFile" }, "keys": "ctrl+alt+," },

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
target 可选Optional "settingsFile""defaultsFile""allFiles""settingsFile", "defaultsFile", "allFiles" 要打开的设置文件。The settings file to open.

重要

字段 target 仅在 Windows 终端预览中可用。The target field is only available in Windows Terminal Preview.

切换全屏Toggle full screen

这允许你在全屏和默认窗口大小之间切换。This allows you to switch between full screen and default window sizes.

命令名称: toggleFullscreenCommand name: toggleFullscreen

默认绑定:Default bindings:

{ "command": "toggleFullscreen", "keys": "alt+enter" },
{ "command": "toggleFullscreen", "keys": "f11" }


选项卡管理命令Tab management commands

关闭选项卡Close tab

这会关闭当前选项卡。This closes the current tab.

命令名称: closeTabCommand name: closeTab

复制选项卡Duplicate tab

这会生成当前选项卡的副本并将其打开。This makes a copy of the current tab and opens it.

命令名称: duplicateTabCommand name: duplicateTab

默认绑定:Default binding:

{ "command": "duplicateTab", "keys": "ctrl+shift+d" }

新建选项卡New tab

这将创建一个新选项卡。如果没有任何参数,这将在新选项卡中打开默认配置文件。如果未指定操作,则将使用默认配置文件的等效设置。This creates a new tab. Without any arguments, this will open the default profile in a new tab. If an action is not specified, the default profile's equivalent setting will be used.

命令名称: newTabCommand name: newTab

默认绑定:Default bindings:

{ "command": "newTab", "keys": "ctrl+shift+t" },
{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+shift+1" },
{ "command": { "action": "newTab", "index": 1 }, "keys": "ctrl+shift+2" },
{ "command": { "action": "newTab", "index": 2 }, "keys": "ctrl+shift+3" },
{ "command": { "action": "newTab", "index": 3 }, "keys": "ctrl+shift+4" },
{ "command": { "action": "newTab", "index": 4 }, "keys": "ctrl+shift+5" },
{ "command": { "action": "newTab", "index": 5 }, "keys": "ctrl+shift+6" },
{ "command": { "action": "newTab", "index": 6 }, "keys": "ctrl+shift+7" },
{ "command": { "action": "newTab", "index": 7 }, "keys": "ctrl+shift+8" },
{ "command": { "action": "newTab", "index": 8 }, "keys": "ctrl+shift+9" }

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
commandLine 可选Optional 字符串形式的可执行文件名Executable file name as a string 可执行文件在选项卡中运行。Executable run within the tab.
startingDirectory 可选Optional 字符串形式的文件夹位置Folder location as a string 将在其中打开该选项卡的目录。Directory in which the tab will open.
tabTitle 可选Optional 字符串String 新选项卡的标题。Title of the new tab.
index 可选Optional 整数Integer 将根据其在下拉列表中的位置打开的配置文件(从 0 开始)。Profile that will open based on its position in the dropdown (starting at 0).
profile 可选Optional 字符串形式的配置文件名称或 GUIDProfile's name or GUID as a string 将根据其 GUID 或名称打开的配置文件。Profile that will open based on its GUID or name.

打开下一个选项卡Open next tab

这会打开当前选项卡右侧的选项卡。This opens the tab to the right of the current one.

命令名称: nextTabCommand name: nextTab

默认绑定:Default binding:

{ "command": "nextTab", "keys": "ctrl+tab" }

打开上一个选项卡Open previous tab

这会打开当前选项卡左侧的选项卡。This opens the tab to the left of the current one.

命令名称: prevTabCommand name: prevTab

默认绑定:Default binding:

{ "command": "prevTab", "keys": "ctrl+shift+tab" }

打开特定的选项卡Open a specific tab

这会打开一个特定的选项卡,具体取决于索引。This opens a specific tab depending on the index.

命令名称: switchToTabCommand name: switchToTab

默认绑定:Default bindings:

{ "command": { "action": "switchToTab", "index": 0 }, "keys": "ctrl+alt+1" },
{ "command": { "action": "switchToTab", "index": 1 }, "keys": "ctrl+alt+2" },
{ "command": { "action": "switchToTab", "index": 2 }, "keys": "ctrl+alt+3" },
{ "command": { "action": "switchToTab", "index": 3 }, "keys": "ctrl+alt+4" },
{ "command": { "action": "switchToTab", "index": 4 }, "keys": "ctrl+alt+5" },
{ "command": { "action": "switchToTab", "index": 5 }, "keys": "ctrl+alt+6" },
{ "command": { "action": "switchToTab", "index": 6 }, "keys": "ctrl+alt+7" },
{ "command": { "action": "switchToTab", "index": 7 }, "keys": "ctrl+alt+8" },
{ "command": { "action": "switchToTab", "index": 8 }, "keys": "ctrl+alt+9" }

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
index 必需Required 整数Integer 将根据其在选项卡栏中的位置打开的选项卡(从 0 开始)。Tab that will open based on its position in the tab bar (starting at 0).


窗格管理命令Pane management commands

关闭窗格Close pane

这会关闭活动窗格。This closes the active pane. 如果没有拆分窗格,将关闭当前选项卡。如果只有一个选项卡处于打开状态,则将关闭该窗口。If there aren't any split panes, this will close the current tab. If there is only one tab open, this will close the window.

命令名称: closePaneCommand name: closePane

默认绑定:Default binding:

{ "command": "closePane", "keys": "ctrl+shift+w" }

移动窗格焦点Move pane focus

这会将焦点更改为其他窗格,具体取决于方向。This changes focus to a different pane depending on the direction.

命令名称: moveFocusCommand name: moveFocus

默认绑定:Default bindings:

{ "command": { "action": "moveFocus", "direction": "down" }, "keys": "alt+down" },
{ "command": { "action": "moveFocus", "direction": "left" }, "keys": "alt+left" },
{ "command": { "action": "moveFocus", "direction": "right" }, "keys": "alt+right" },
{ "command": { "action": "moveFocus", "direction": "up" }, "keys": "alt+up" }

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
direction 必需Required "left""right""up""down""left", "right", "up", "down" 焦点将移动的方向。Direction in which the focus will move.

调整窗格大小Resize a pane

这会更改活动窗格的大小。This changes the size of the active pane.

命令名称: resizePaneCommand name: resizePane

默认绑定:Default bindings:

{ "command": { "action": "resizePane", "direction": "down" }, "keys": "alt+shift+down" },
{ "command": { "action": "resizePane", "direction": "left" }, "keys": "alt+shift+left" },
{ "command": { "action": "resizePane", "direction": "right" }, "keys": "alt+shift+right" },
{ "command": { "action": "resizePane", "direction": "up" }, "keys": "alt+shift+up" }

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
direction 必需Required "left""right""up""down""left", "right", "up", "down" 调整窗格大小的方向。Direction in which the pane will be resized.

拆分窗格Split a pane

这会将活动窗格的大小减半,并打开另一个窗格。This halves the size of the active pane and opens another. 如果没有任何参数,这将在新窗格中打开默认配置文件。Without any arguments, this will open the default profile in the new pane. 如果未指定操作,则将使用默认配置文件的等效设置。If an action is not specified, the default profile's equivalent setting will be used.

命令名称: splitPaneCommand name: splitPane

默认绑定:Default bindings:

// In settings.json
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" },

// In defaults.json
{ "command": { "action": "splitPane", "split": "horizontal"}, "keys": "alt+shift+-" },
{ "command": { "action": "splitPane", "split": "vertical"}, "keys": "alt+shift+plus" }

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
split 必需Required "vertical""horizontal""auto""vertical", "horizontal", "auto" 窗格的拆分方式。How the pane will split. "auto" 将沿具有最大表面积的方向进行拆分。"auto" will split in the direction that provides the most surface area.
commandLine 可选Optional 字符串形式的可执行文件名Executable file name as a string 可执行文件在窗格中运行。Executable run within the pane.
startingDirectory 可选Optional 字符串形式的文件夹位置Folder location as a string 将在其中打开该窗格的目录。Directory in which the pane will open.
tabTitle 可选Optional 字符串String 聚焦于新窗格时选项卡的标题。Title of the tab when the new pane is focused.
index 可选Optional 整数Integer 将根据其在下拉列表中的位置打开的配置文件(从 0 开始)。Profile that will open based on its position in the dropdown (starting at 0).
profile 可选Optional 字符串形式的配置文件名称或 GUIDProfile's name or GUID as a string 将根据其 GUID 或名称打开的配置文件。Profile that will open based on its GUID or name.
splitMode 可选Optional "duplicate" 控制窗格拆分的方式。Controls how the pane splits. 仅接受 "duplicate",这会将焦点窗格的配置文件复制到新窗格中。Only accepts "duplicate", which will duplicate the focused pane's profile into a new pane.


剪贴板集成命令Clipboard integration commands

复制Copy

这会将所选终端内容复制到剪贴板。This copies the selected terminal content to your clipboard.

命令名称: copyCommand name: copy

默认绑定:Default bindings:

// In settings.json
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+c" },

// In defaults.json
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+shift+c" },
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+insert" }

剪贴板操作Clipboard Actions

名称Name 必要性Necessity 接受Accepts 说明Description
singleLine 可选Optional truefalsetrue, false true 时,复制的内容将复制为单一的一行。When true, the copied content will be copied as a single line. false 时,则将从所选文本保留换行符。When false, newlines persist from the selected text.

粘贴Paste

这会插入复制到剪贴板上的内容。This inserts the content that was copied onto the clipboard.

命令名称: pasteCommand name: paste

默认绑定:Default bindings:

// In settings.json
{ "command": "paste", "keys": "ctrl+v" },

// In defaults.json
{ "command": "paste", "keys": "ctrl+shift+v" },
{ "command": "paste", "keys": "shift+insert" }


回滚命令Scrollback commands

向上滚动Scroll up

这会向上滚动屏幕。This scrolls the screen up.

命令名称: scrollUpCommand name: scrollUp

默认绑定:Default binding:

{ "command": "scrollUp", "keys": "ctrl+shift+up" }

向下滚动Scroll down

这会向下滚动屏幕。This scrolls the screen down.

命令名称: scrollDownCommand name: scrollDown

默认绑定:Default binding:

{ "command": "scrollDown", "keys": "ctrl+shift+down" }

向上滚动一整页Scroll up a whole page

这会将屏幕向上滚动一整页(即窗口的高度)。This scrolls the screen up by a whole page, which is the height of the window.

命令名称: scrollUpPageCommand name: scrollUpPage

默认绑定:Default binding:

{ "command": "scrollUpPage", "keys": "ctrl+shift+pgup" }

向下滚动一整页Scroll down a whole page

这会将屏幕向下滚动一整页(即窗口的高度)。This scrolls the screen down by a whole page, which is the height of the window.

命令名称: scrollDownPageCommand name: scrollDownPage

默认绑定:Default binding:

{ "command": "scrollDownPage", "keys": "ctrl+shift+pgdn" }


视觉对象调整命令Visual adjustment commands

调整字号Adjust font size

这会将文本大小更改为指定的磅值。This changes the text size by a specified point amount.

命令名称: adjustFontSizeCommand name: adjustFontSize

默认绑定:Default bindings:

{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+=" },
{ "command": { "action": "adjustFontSize", "delta": -1 }, "keys": "ctrl+-" }

“操作”Actions

名称Name 必要性Necessity 接受Accepts 说明Description
delta 必需Required 整数Integer 每次命令调用的大小更改量。Amount of size change per command invocation.

重置字号Reset font size

这会将文本大小重置为默认值。This resets the text size to the default value.

命令名称: resetFontSizeCommand name: resetFontSize

默认绑定:Default binding:

{ "command": "resetFontSize", "keys": "ctrl+0" }


取消绑定键Unbind keys

这将从任何命令取消绑定关联键。This unbinds the associated keys from any command.

命令名称: unboundCommand name: unbound