Home > Software design >  How to type a shorthand and expand it as a line of code in vscode?
How to type a shorthand and expand it as a line of code in vscode?

Time:09-01

Is it possible to type a shorthand for a line of code eg: breakpoint() in vscode, so that I don't have to type it fully every time.

CodePudding user response:

I use Go to File --> Preferences --> Configure User Snippets.

Provide a name for the snippet, and click enter. (Make it global if you want)

Now type the following code to make a multi line snippet (The code used in the snippet is for Python. You can use your required one)

{
    "My simple snippet": {
        "prefix": "mysnip",
        "body": [
            "if __name__ == '__main__':",
            "    # code goes here",
        ],
        "description": "Creates a if __name__ statement"
    }
}

Now when you type mysnip in vscode, it will show the suggestion in the intellisense.

The following is the output that I get:

if __name__ == '__main__':
    # code goes here

Source

  • Related