Is there any way to autoload the PyGame skeleton in VS Code?

Question:

I recently started learning with PyGame and I’m getting tired of writing the basic skeleton over and over again. Is there any way to make Visual Studio Code autoload the skeleton for me?

For example in HTML, when you write an exclamation mark (!) and then press the tab key, it autoloads the basic HTML skeleton.

Would be OK for me, if there was any built-in way to do this. But it would be even better, if I could define the skeleton by myself (because I like to put comments there and I’m used to a particular order of the skeleton) and then connect it to some shorcut or something.

Asked By: robin

||

Answers:

Code snippets may be useful to you.

Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements.

Here is the official document introduction

  • Click on the gear icon at the bottom left of vscode, then select Configure User Snippets

    enter image description here

  • Choose python in the list

    enter image description here

At this time, vscode will automatically create a file named python.json. There you can customize code snippets.

A small example

code in “python.json`

    "Print to console": {
        "prefix": "defHello",
        "body": [
            "def Hello():",
            "${1:    }print('Hello world')",
            "$2",
        ],
        "description": "print hello world"
    }

When you type def..., there will be a corresponding intellisense

enter image description here

Enter to select, automatically insert the statement you configured.

enter image description here

Answered By: JialeDu