如何使代码段格式成为变量

问题描述 投票:0回答:1

是否可以制作一个片段来生成如下所示的代码,同时只使用一个制表位?或者至少在用户点击时将

SomeVar
作为占位符。

const someVar = SomeVarClass();

我目前的尝试无法识别

pascalcase

{
  "Initialize variable to it's class": {
    "prefix": "ivtc",
    "body": [
      "const ${1:someVar} = ${1:/pascalcase}Class()",
    ],
  }
}
visual-studio-code code-snippets textmate vscode-snippets
1个回答
0
投票

当点击转换时,解决方案看起来像

{
  "Initialize variable to it's class": {
    "prefix": "ivtc",
    "body": [
      "const ${1:someVar} = ${1/(.*)/${1:/pascalcase}/}Class();",
    ],
  }
}

然后我可以通过包装将之前的转换用作变量

{
  "Initialize variable to it's class": {
    "prefix": "ivtc",
    "body": [
      "const ${1:someVar} = ${2:${1/(.*)/${1:/pascalcase}/}}Class();",
      "$2",
    ],
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.