如何在Visual Studio Code中“安装”字体以供使用?

我有这个漂亮的等宽字体https://github.com/tonsky/FiraCode,我想在Ubuntu的Visual Studio Code中使用它。

我下载了字体文件(.ttf),我了解到要使字体系统范围可用,我必须将其复制到/usr/share/fonts,所以我使用sudo将这些文件复制到/usr/share/fonts/truetype/fira-code

我注意到复制后的权限是750,所以我改变了权限为755

现在我进入Visual Studio Code首选项并告诉它我将使用"Fira Code",但没有任何反应。如果我将其更改为例如"DejaVu Sans Mono",它将使用该字体。

这样做后,我在LibreOffice中也看不到这些字体.

此失败之后,我在我的主目录中创建了一个.fonts目录,并复制了.ttf文件,结果相同。(我按照此处的说明进行操作:https://itsfoss.com/install-fonts-ubuntu-1404-1410/

复制字体到这里,我在LibreOffice中可以看到它们,但是在Visual Studio Code中无法使用。
看起来好像有一种“字体注册表”,你如何在Ubuntu中正确安装字体文件?

FiraCode开发者的GitHub页面表示支持Visual Studio Code。也许你可以向开发者寻求帮助? - WinEunuuchs2Unix
我认为这是一般的,与这种字体无关 - luisfer
可能是VSC上的配置问题,或者只是某种设置问题。 - luisfer
1个回答

要设置这些漂亮的字体,请按照以下步骤进行操作。
  1. 这里下载字体

  2. 解压缩并在ttf文件夹中双击每个文件,然后从弹出的对话框中选择“安装”

  3. 设置VSCode:

    1. 打开“文件 -> 首选项 -> 设置”
    2. 右上角点击{},将打开用户设置(settings.json)
    3. 添加以下行:

      "editor.fontFamily": "'Fira Code'",
      "editor.fontLigatures": true,
      
      • 注意:我必须注释掉正常的字体族输入,以便可以通过反转过程切换回去。
    4. 要更改字体粗细,请添加以下任意一行,但不要全部添加

      "editor.fontWeight": "300" // 轻
      "editor.fontWeight": "400" // 常规
      "editor.fontWeight": "500" // 中等
      "editor.fontWeight": "600" // 粗体
      
  4. 重新启动并享受。

    enter image description here

我的示例用户settings.json
{
    "files.autoSave": "onFocusChange",
    "editor.minimap.enabled": false,
    "workbench.iconTheme": "material-icon-theme",
    "vsicons.projectDetection.autoReload": true,
    "workbench.editor.enablePreview": false,
    "workbench.editor.enablePreviewFromQuickOpen": false,
    // "editor.fontFamily": "'Noto Mono', 'Droid Sans Mono', 'Courier New', monospace, 'Droid Sans Fallback'",
    "breadcrumbs.enabled": true,
    "typescript.updateImportsOnFileMove.enabled": "always",
    "git.enableSmartCommit": true,
    "java.home": "/usr/lib/jvm/java-8-oracle",
    // "editor.fontLigatures": true,
    "editor.fontFamily": "'Fira Code', 'Noto Mono', 'Droid Sans Mono', 'Courier New', monospace, 'Droid Sans Fallback'",
    "editor.fontLigatures": true,
    // "editor.fontWeight": "300", // Light
    // "editor.fontWeight": "400", // Regular
    // "editor.fontWeight": "500", // Medium
    // "editor.fontWeight": "600" // Bold
}