Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I customize python syntax highlighting in VS code?

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)

What should I do?

like image 516
JehunYoo Avatar asked Jul 14 '19 04:07

JehunYoo


People also ask

How do I change the syntax highlighting in VS Code?

To change the text and syntax colors in visual studio code follow the steps given below: Open VS Code editor to change the syntax colors. Go to Settings, which is on the bottom left corner of the VS Code window. In the search field type JSON, and click on the 'Edit in settings.

How do you change the syntax highlight color scheme?

Enable semantic highlightingPress Ctrl+Alt+S to open the IDE settings and select Editor | Color Scheme | Language Defaults | Semantic highlighting.


1 Answers

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.

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"

Before and After

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"

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.

Here's how it looks with pandas.DataFrame():

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.

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

like image 136
Stoockbroker Avatar answered Oct 09 '22 21:10

Stoockbroker