使用命令面板可以查看可在 Windows 终端中运行的操作。 有关如何定义操作的更多信息,请参阅 操作页面。
调用命令面板
可以通过键入 Ctrl+Shift+P 来调用命令面板。 可以通过将 commandPalette 命令添加到快捷键绑定来进行个性化设置。
{ "command": "commandPalette", "keys": "ctrl+shift+p" }
命令行模式
如果要在命令面板中输入 wt 命令,可以通过删除文本框中的 > 字符来执行此作。 这将在当前窗口中运行 wt 命令。 有关命令的详细信息 wt ,请参阅 命令行参数页。
可以添加自定义键绑定,以便直接在命令行模式下调用命令面板。
{ "command": "commandPalette", "launchMode": "commandLine", "keys": "" }
向命令添加图标
可以选择将图标添加到命令面板中显示的 settings.json 中定义的命令。 可以通过将 icon 属性添加到操作来完成此操作。 图标可以是图像的路径、 Segoe MDL2 Assets 中的符号或任何字符,包括表情符号。
{ "icon": "C:\\Images\\my-icon.png", "name": "New tab", "command": "newTab", "keys": "ctrl+shift+t" },
{ "icon": "\uE756", "name": "New tab", "command": "newTab", "keys": "ctrl+shift+t" },
{ "icon": "⚡", "name": "New tab", "command": "newTab", "keys": "ctrl+shift+t" }
注释
从 Windows 终端 1.24 开始, icon 可能引用文件 settings.json 旁边的内容。
嵌套命令
嵌套命令允许在命令面板中的一项下对多个命令进行分组。 以下示例将字体大小调整命令分组到名为“更改字号...”的一个命令面板项下。
{
"name": "Change font size...",
"commands": [
{ "command": { "action": "adjustFontSize", "delta": 1 } },
{ "command": { "action": "adjustFontSize", "delta": -1 } },
{ "command": "resetFontSize" },
]
}
可迭代命令
可迭代命令允许同时创建多个命令,这些命令是从设置中定义的其他对象生成的。 目前,可以为配置文件和配色方案创建可迭代命令。 在运行时,这些命令将扩展到给定类型的每个对象的一个命令。
当前可循环访问以下属性:
iterateOn |
资产 | 属性语法 |
|---|---|---|
profiles |
name |
"name": "${profile.name}" |
profiles |
icon |
"icon": "${profile.icon}" |
schemes |
name |
"name": "${scheme.name}" |
Example
为每个配置文件创建新的标签命令。
{
"iterateOn": "profiles",
"icon": "${profile.icon}",
"name": "${profile.name}",
"command": { "action": "newTab", "profile": "${profile.name}" }
}
在上面的示例中:
-
"iterateOn": "profiles"将为每个配置文件生成一个命令。 - 在运行时,终端将每个配置文件的图标替换为
${profile.icon},并将每个配置文件的名称替换为${profile.name}。
如果你有三个个人资料:
"profiles": [
{ "name": "Command Prompt", "icon": null },
{ "name": "PowerShell", "icon": "C:\\path\\to\\icon.png" },
{ "name": "Ubuntu", "icon": null },
]
上述命令的行为类似于以下三个命令:
{
"icon": null,
"name": "Command Prompt",
"command": { "action": "newTab", "profile": "Command Prompt" }
},
{
"icon": "C:\\path\\to\\icon",
"name": "PowerShell",
"command": { "action": "newTab", "profile": "PowerShell" }
},
{
"icon": null,
"name": "Ubuntu",
"command": { "action": "newTab", "profile": "Ubuntu" }
}
还可以组合嵌套和可迭代命令。 例如,可以在命令面板中的单个“新建选项卡”条目下组合上述三个“新建选项卡”命令,如上图所示,如下所示:
{
"name": "New tab",
"commands": [
{
"iterateOn": "profiles",
"icon": "${profile.icon}",
"name": "${profile.name}",
"command": { "action": "newTab", "profile": "${profile.name}" }
}
]
}
隐藏命令
如果想保留键绑定列表中的命令,但不希望它出现在命令面板中,可以通过将相关配置设置为 name 以 null 的方式来隐藏它。 下面的示例隐藏命令面板中的“新建选项卡”作。
{ "name": null, "command": "newTab", "keys": "ctrl+shift+t" }