How can I change the coloring of parentheses and brackets?

£可爱£侵袭症+ 提交于 2019-12-09 13:42:14

问题


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]  


回答1:


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


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.

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):

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"
            }
        }
    ]
}

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.

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

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.

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).



来源:https://stackoverflow.com/questions/55089057/how-can-i-change-the-coloring-of-parentheses-and-brackets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!