Search code examples
pythonjsonvisual-studio-codevscode-snippets

Is it possible to highlight vscode snippets variables?


I have written a vscode snippet for a python function definition with a block comment. However, block comments are not always needed.

I'd like to be able to traverse to the inside of the block comment and then to the highlighted block comment for fast deletion if neccesary.

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

Desired output

enter image description here


Solution

  • Try wrapping that whole block comment in a tabstop:

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

    \t${3:$BLOCK_COMMENT_START $2 $BLOCK_COMMENT_END} or
    "${3:\t$BLOCK_COMMENT_START $2 $BLOCK_COMMENT_END}" with the \t included in the selection.

    Then after $2, and tab all of the block comment start and end will be selected and you can delete it if you wish.

    block comment snippet wrap