Basketball ICO
Basketball ICO

Reputation: 49

In VS code snippet how to reuse a transforms like a variable to avoid write the transform again and again?

For example I want to reuse this transform like a variable in my snippet instead of write the transform again and again

${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}
    "example": {
        "prefix": "example",
        "body": [
            "${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/} ${1:name1} = _${1};",
            "${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/} ${2:name2} = _${2};",
            "${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/} ${3:name3} = _${3};",
            //...
        ],
        "description": "example"
    },

Upvotes: 4

Views: 797

Answers (1)

Kyle Wilichowski
Kyle Wilichowski

Reputation: 41

You can repeat the same transform by assigning it to a placeholder and referencing that number, like this:

  "example": {
    "prefix": "example",
    "body": [
      "${4:${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}} ${1:name1} = _${1};",
      "${4} ${2:name2} = _${2};",
      "${4} ${3:name3} = _${3};",
    ]
  }

Upvotes: 4

Related Questions