如何在 VS 代码中自定义 python 语法突出显示? [英] How can I customize python syntax highlighting in VS code?

查看:30
本文介绍了如何在 VS 代码中自定义 python 语法突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Anaconda 安装了 Visual Studio Code,并且想要自定义语法高亮.我正在使用默认的深色主题,这很好,但 python 内置函数和方法的颜色不是.

I installed Visual Studio Code with Anaconda, and want to customize syntax highlight. I'm using default dark theme and that's good but colors of python built-in functions and methods aren't.

我找到了开发人员:从当前设置生成颜色主题"并试图找到更改的位置.(我不确定改变语法高亮颜色的文件是否正确)

I found 'Developer : Generate Color Theme From Current Settings' and tried to find where to change. (I'm not sure if it is right file to change colors of syntax highlight)

我该怎么办?

推荐答案

在 Visual Studio Code 中,您可以使用内置的颜色主题,安装由社区创建并上传到 Marketplace 的新颜色主题或编辑已经存在的颜色主题.如果您只想自定义语法的特定颜色,例如函数名,需要编辑settings.json文件.

In Visual Studio Code you can use color themes which are built-in, install new created by community and uploaded to Marketplace or edit allready existed. If you only want to customize a specific color of syntax e.g. function name, you need to edit settings.json file.

要执行此操作,请转到 文件 >首选项设置 >工作台外观和在颜色自定义部分点击在settings.json中编辑

To do this go to File > Preferences > Settings > Workbench > Appearance and in sections Color Customizations click on Edit in settings.json

现在您需要通过在此文件中添加代码并保存它来指定您想要自定义的确切内容.

Now you need to specify what exactly you want customize by adding code in this file and just save it.

此代码会将函数名称的颜色更改为橙​​色:

This code will change color of function name to orange:

"editor.tokenColorCustomizations": {
"functions": "#FF9900"

如果您想更改一些其他设置,例如变量、字符串、数字遵循以下模式:

If you want to change some other settings e.g. variables, strings, numbers follow this pattern:

"editor.tokenColorCustomizations": {
"what_you_want_to_customize" : "hex_value_of_color"

如果你想在调用方法时改变颜色,你需要指定范围(在同一个 settings.json 文件中):

If you want to change color when you call methods you need to specify scope (in the same settings.json file):

"editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "meta.function-call",
                "settings": {
                    "foreground": "#FF9900"
                }
            }

现在,当您在某些对象中调用函数时,它会显示为橙色.

Now when you call function in some objects it will appear as orange color.

以下是 pandas.DataFrame() 的外观:

如果您在对象中创建自己的方法,它也将是您选择的颜色.

If you create your own method in objects it will also be color of your choice.

这就是你结合这两个设置时的样子.

And this is how it looks when you combine this two settings.

为了更好的解释,我只是在创建函数时将颜色更改为红色,在调用函数时将颜色更改为橙​​色.

I've just change color to red when function is created and orange when function is called for better explanation.

还有官方文档供进一步阅读和更多设置自定义外观(文本、条形、按钮).

There is also official docs for further reading and much more settings to make it custom looks (text, bars, buttons).

这篇关于如何在 VS 代码中自定义 python 语法突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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