Home > Software engineering >  How to escape python block comments when creating vscode snippets?
How to escape python block comments when creating vscode snippets?

Time:01-03

I created a vscode snippet for a a python function definiton and I am wondering if this is the only and/or recommended way of escaping the python block comments (""" """).

global snippets file

{   
    "def ": {
            "scope": "python",
            "prefix": "def func",
            "body": [
                "def $1 ():
                \"\"\"\" \"\"\"\    "
            ],
            "description": "Python function"
    }
}

output

def  ():  
""" """   

CodePudding user response:

Specify each line in a separate string of the body:

You can choose the kind of doc string delimiters.

The doc string should be indented (\t) and the body.

{   
  "def": {
    "scope": "python",
    "prefix": "def func",
    "body": [
      "def $1 ():",
      "\t${2|\"\"\",''',\",'|} $3 $2",
      "\t$0"
    ],
    "description": "Python function"
  }
}

CodePudding user response:

I just saw that vscode has a built in variable for block comments. The code after the block comment should be indented, too.


"def": {
        "scope": "python",
        "prefix": "def func",
        "body": [
            "def $1 ():",
            "\t$BLOCK_COMMENT_START $2 $BLOCK_COMMENT_END",
            "\t$0"
        ],
        "description": "Python function"

  • Related