如何获得Visual Studio Code以格式化代码显示斜体字体? [英] How do I get Visual Studio Code to display italic fonts in formatted code?

查看:506
本文介绍了如何获得Visual Studio Code以格式化代码显示斜体字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置VS Code以支持斜体样式(如上图所示)?

How do I configure VS Code to support italic styles, like in this picture?

我当前的设置:

{
  "editor.fontLigatures": true,
  "editor.fontFamily": "Operator Mono"
}

推荐答案

对此问题的直接答案是( 从此github页面 ):

将其添加到settings.json(ctrl + ,cmd + ,)

The direct answer to this question is (from this github page):

Add this to settings.json (ctrl + , or cmd + ,)

"editor.tokenColorCustomizations": {
  "textMateRules": [
    {
      "scope": [
        //following will be in italic (=FlottFlott)
        "comment",
        "entity.name.type.class", //class names
        "keyword", //import, export, return…
        "constant", //String, Number, Boolean…, this, super
        "storage.modifier", //static keyword
        "storage.type.class.js", //class keyword
      ],
      "settings": {
        "fontStyle": "italic"
      }
    },
    {
      "scope": [
        //following will be excluded from italics (VSCode has some defaults for italics)
        "invalid",
        "keyword.operator",
        "constant.numeric.css",
        "keyword.other.unit.px.css",
        "constant.numeric.decimal.js",
        "constant.numeric.json"
      ],
      "settings": {
        "fontStyle": ""
      }
    }
  ]
}

您当然也可以在scope中提供其他关键字.查看 VS Code的文档范围关键字.

You can also provide other keywords in scope of course. Check VS Code's documentation and the scope keywords.

当您为VS Code定义字体时(例如,OP的Operator Mono),所有内容均以该字体呈现.为了获得OP图像的外观,您需要对某些元素应用不同的字体样式(斜体/粗体).另外,如果您的字体具有明显不同的斜体样式(例如Operator Mono具有草书连字),您将获得与OP图像相似的外观.

When you define a font for VS Code (e.g. Operator Mono for the OP), everything is rendered in that font. In order to achieve the look in the OP's image, you need to apply a different font style (italic/bold) to certain elements. Also, if your font has a significantly different italics style (e.g. Operator Mono has cursive ligatures), you will get a similar look to the OP's image.

为了使您的斜体与普通文本看起来不同,您需要使用一种斜体外观不同的字体.这样的字体是OperatorMono(付费)或 FiraCodeiScript (免费),或

In order for your italics to look different than your normal text, you need to be using a font whose italics, look different. Such a font is OperatorMono (paid), or FiraCodeiScript (free), or FiraFlott (free). I personally prefer FiraCodeiScript.

要使斜体字符链接在一起(它们之间没有空格),就像写草书一样,您需要启用字体连字:

To make the italic characters linked, (not have spacing between them), like writing cursive, you need to enable font ligatures:

要执行上述操作,请确保您的settings.json具有以下内容:

To do the above, make sure that your settings.json has the following:

{
  "editor.fontLigatures": true,
  "editor.fontFamily": "'Fira Code iScript', Consolas, 'Courier New', monospace"
}

不需要其余的字体,但是如果您缺少第一个字体,它们是备用字体.名称中带有空格的字体通常需要单引号'.另外,您可能需要重新启动VS Code.

The rest of the fonts are not needed, but they are fallback fonts in case that you are missing the first. Fonts with spaces in their names, usually need single quotes'. Also, you might need to restart VS Code.

这篇关于如何获得Visual Studio Code以格式化代码显示斜体字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆