排查 Windows 终端中的问题Troubleshooting in Windows Terminal

本指南解决了使用 Windows 终端时可能会遇到的一些常见错误和障碍。This guide addresses some of the common errors and obstacles you may encounter when using Windows Terminal.

将 WSL 分发设置为启动时在主 ~ 目录中开始Set your WSL distribution to start in the home ~ directory when launched

默认情况下,配置文件的 startingDirectory%USERPROFILE% (C:\Users\<YourUsername>)。By default, the startingDirectory of a profile is %USERPROFILE% (C:\Users\<YourUsername>). 这是一个 Windows 路径。This is a Windows path. 但对于 WSL,可能需要改用 WSL 主路径。For WSL, however, you may want to use the WSL home path instead. startingDirectory 仅接受 Windows 样式路径,因此将其设置为在 WSL 分发中启动需要使用前缀。startingDirectory only accepts a Windows-style path, so setting it to start within a WSL distribution requires a prefix.

从 Windows 10 版本 1903 开始,可以使用 \\wsl$\ 前缀来寻址 WSL 分发的文件系统。Beginning in Windows 10 version 1903, the file systems of WSL distributions can be addressed using the \\wsl$\ prefix. 对于名称为 DistroName 的任何 WSL 分发,请使用 \\wsl$\DistroName 作为 Windows 路径,该路径指向该分发文件系统的根目录。For any WSL distribution with the name DistroName, use \\wsl$\DistroName as a Windows path that points to the root of that distribution's file system.

例如,以下设置会在其主文件路径中启动“Ubuntu-18.04”分发:For example, the following setting will launch the "Ubuntu-18.04" distribution in its home file path:

{
    "name": "Ubuntu-18.04",
    "commandline" : "wsl -d Ubuntu-18.04",
    "startingDirectory" : "//wsl$/Ubuntu-18.04/home/<Your Ubuntu Username>",
}

设置选项卡标题Setting the tab title

若要使 shell 自动设置选项卡标题,请访问设置选项卡标题教程To have the shell automatically set your tab title, visit the set the tab title tutorial. 如果要设置自己的选项卡标题,请打开 settings.json 文件,然后执行以下步骤:If you want to set your own tab title, open the settings.json file and follow these steps:

  1. 在所选命令行的配置文件中,添加 "suppressApplicationTitle": true 以禁止 shell 发出的任何标题更改事件。In the profile for the command line of your choice, add "suppressApplicationTitle": true to suppress any title change events that get sent from the shell. 仅将此设置添加到配置文件会将选项卡标题设置为配置文件的名称。Adding only this setting to your profile will set the tab title to the name of your profile.

  2. 如果需要不是配置文件名称的自定义选项卡标题,请添加 "tabTitle": "TITLE"If you want a custom tab title that is not the name of your profile, add "tabTitle": "TITLE". 用首选选项卡标题替换“TITLE”。Replacing "TITLE" with your preferred tab title.

PowerShell 中的命令行参数Command line arguments in PowerShell

请访问命令行参数页,了解命令行参数在 PowerShell 中的运作方式。Visit the Command line arguments page to learn how command-line arguments operate in PowerShell.

WSL 中的命令行参数Command line arguments in WSL

请访问命令行参数页,了解命令行参数在 WSL 中的运作方式。Visit the Command line arguments page to learn how command-line arguments operate in WSL.

设置 startingDirectory 时出现的问题Problem setting startingDirectory

如果配置文件中忽略 startingDirectory,请先检查以确保你的 settings.json 的语法是正确的。If the startingDirectory is being ignored in your profile, first check to make sure your settings.json's syntax is correct. 为了帮助检查此语法,"$schema": "https://aka.ms/terminal-profiles-schema" 会自动注入。To help you check this syntax, "$schema": "https://aka.ms/terminal-profiles-schema" is automatically injected. 某些应用程序(如 Visual Studio Code)在你进行编辑时,可以使用这个注入的架构来验证 json 文件。Some applications, like Visual Studio Code, can use that injected schema to validate your json file as you make edits.

如果设置正确,则可能正在运行一个启动脚本,该脚本单独设置终端的起始目录。If your settings are correct, you may be running a startup script that sets the starting directory of your terminal separately. 例如,PowerShell 具有自己单独的配置文件概念。For example, PowerShell has its own separate concept of profiles. 如果在此处更改起始目录,它将优先于在 Windows 终端中定义的设置。If you are changing your starting directory there, it will take precedence over the setting defined in Windows Terminal.

或者,如果正在使用 commandline 配置文件设置运行脚本,则可能是在此处设置位置。Alternatively, if you are running a script using the commandline profile setting, it may be that you are setting the location there. 类似于 PowerShell 配置文件,此处命令的优先级高于 startingDirectory 配置文件设置。Similar to PowerShell profiles, your commands there take precedence over the startingDirectory profile setting.

startingDirectory 的目的是在给定目录中启动新的 Windows 终端实例。The purpose of startingDirectory is to launch a new Windows Terminal instance in the given directory. 如果终端运行更改其目录的任何代码,那么这里可能是进行查看的不错位置。If the terminal runs any code that changes its directory, that may be a good place to take a look.

Ctrl+= 不会增加字体大小Ctrl+= does not increase the font size

如果使用德语键盘布局,则可能会遇到此问题。If you are using a German keyboard layout, you may run into this problem. 如果将主键盘布局设置为德语,则 ctrl+= 将反序列化为 ctrl+shift+0ctrl+= gets deserialized as ctrl+shift+0 if your main keyboard layout is set to German. 这是德语键盘的正确映射。This is the correct mapping for German keyboards.

更重要的是,应用永远不会收到 ctrl+shift+0 击键。More importantly, the app never receives the ctrl+shift+0 keystroke. 这是因为如果有多个活动的键盘布局,则 Windows 将保留 ctrl+shift+0This is because ctrl+shift+0 is reserved by Windows if you have multiple keyboard layouts active.

若要禁用此功能以便 Ctrl+= 正常运行,请按照此博客文章中的“更改 Windows 10 中切换键盘布局的热键”说明进行操作。If you would like to disable this feature in order for Ctrl+= to work properly, follow the instructions for "Change Hotkeys to Switch Keyboard Layout in Windows 10" in this blog post.

将“切换键盘布局”选项更改为“未分配”(或关闭 ctrl+shift),然后依次选择“确定”、“应用” 。Change the 'Switch Keyboard Layout' option to 'Not Assigned' (or off of ctrl+shift), then select OK and then Apply. ctrl+shift+0 现在应作为键绑定工作,并传递给终端。ctrl+shift+0 should now work as a key binding and is passed through to the terminal.

另一方面,如果对多种输入语言使用此热键功能,则可以在 settings.json 文件中配置自己的自定义键绑定On the other hand, if you do use this hotkey feature for multiple input languages, you can configure your own custom key binding in your settings.json file.

文本模糊The text is blurry

如果不对上一帧中的数据进行模糊处理,某些显示驱动程序和硬件组合就无法正常处理滚动和/或脏区域。Some display drivers and hardware combinations do not handle scroll and/or dirty regions without blurring the data from the previous frame. 若要缓解此问题,可以添加这些全局呈现设置的组合,以降低由于终端文本呈现器导致的硬件显示拉伸。To mitigate this problem, you can add a combination of these global rendering settings to reduce the strain placed on your hardware caused by the terminal text renderer.