如何更改圆括号和方括号的颜色? [英] How can I change the coloring of parentheses and brackets?

查看:46
本文介绍了如何更改圆括号和方括号的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个一般性的 vsCode 问题,但我试图让它在 vsCode 的 Microsoft Python 插件中工作.
在编辑设置文件时,我尝试了所有显示为智能感知建议的 textMate 定义,但都没有奏效.

This might be a general vsCode question, but I'm trying to make it work in the Microsoft Python plugin for vsCode.
I tried all the textMate definitions that show as intellisense suggestions when editing the settings file but none worked.

我想为括号、大括号和;括号或任何其他标记,以便在前面的标识符(函数名称或集合名称)和分隔符(函数参数或集合索引)内的内容之间产生视觉差异

I want to either colorize the parentheses, braces & brackets or any other token in order to make a visual difference between the preceding identifier (function name or collection name) and what goes inside the delimiters (function arguments or collection indices)

function(arg1, arg2)
collection[index]  

推荐答案

在 Visual Studio Code 中,您可以根据您的个人需求自定义许多语法颜色.

In Visual Studio Code, you can customize a lot of syntax colors to your individual needs.

假设我们要更改特定逗号的语法颜色 - 例如用于分隔函数参数的那个 - 您需要知道该标记具有什么标识符.要找出这一点,只需点击ctrl+shift+P 并输入Developer: Inspect TM Scopes.

Let's say we want to change syntax color of a specific comma - for example the one used to seperate function parameters - you'll need to know what identifier that token has. To find out this just hit ctrl+shift+P and type in Developer: Inspect TM Scopes.

然后单击打开的脚本内的任意位置,然后选择您想了解更多信息的所需字符或关键字.正如您在下面看到的,Python 中函数参数之间的逗号标识符是 punctuation.separator.parameters.python(顺便说一句,还有一个名为 punctuation.separator.arguments.pythoncode>,所以你甚至可以为参数之间的逗号使用不同的颜色):

Then click anywhere inside an opened script and select the desired character or keyword you want to know more about. As you can see below the identifier for commas between function parameters in Python is punctuation.separator.parameters.python (btw. there is also a token named punctuation.separator.arguments.python, so you could even use a different color for the commas between arguments):

既然您拥有该令牌所需的标识符,您可以将以下内容添加到您的 settings.json 中:

Now that you have the required identifier for that token, you can add the following to your settings.json:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
        "scope": "punctuation.separator.parameters.python",
            "settings": {
                "foreground": "#ff8800",
                "fontStyle": "bold"
            }
        }
    ]
}

如您所见,您不仅可以更改颜色,还可以根据需要更改字体样式,并且可以在 "textMateRules" 中放置任意数量的范围想.

As you can see you're not only able to change the color, you're also able to change font style if you want and you can place as many scopes within "textMateRules" as you want.

这适用于圆括号、方括号和大括号以及冒号、任何类型的运算符、关键字如 classdef 等.

This works for parentheses, brackets and curly brackets as well as for colons, any kind of operators, keywords like class, def, etc.

通过这种方式,您可以调整语法着色,而无需更改整个主题.当然,您可以使用 VSCode 中几乎所有可用的语言来执行此操作.

In this way you can adjust syntax coloring without having to change the whole theme. And of course you can do this with nearly every language available in VSCode.

注意:以上代码仅将更改应用于 Python 语言,并且只会在 Python 脚本中显示所选颜色.对于其他编程语言,您首先必须检查所需语言的代码(如上所述)以找出令牌的标识符(不幸的是,我还没有找到可供选择的所有可用令牌的列表,因此,如果有人知道从哪里或如何获得它,请随时添加评论 - 谢谢).

Note: The code above applies changes only to Python language and will display the selected colors only in Python scripts. For other programming languages you'll first have to inspect the code of the desired language (like described above) to find out the identifiers of the tokens (unfortunately I've not yet found a list of all available tokens to choose from, so, if somebody knows from where or how to get it, feel free to add a comment - thx).

这篇关于如何更改圆括号和方括号的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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