修改 VSCode 中用户代码段中参数的第一个字母
Modify the first letter of an argument in a user snippet in VSCode
我正在使用前缀 prop
生成:
private ;
public void set( ) {
this. = ;
}
public get() {
return ;
}
这是我的代码片段:
"Add a property" : {
"prefix": "prop",
"body": [
"private ;",
"public get() {",
"\treturn ;",
"}",
"public void set( ) {",
"\tthis. = ;",
"}"
],
"description": "Add a property to class"
}
输出:
private int age;
public int getage() {
return age;
}
public void setage(int age) {
this.age = age;
}
预期输出:
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
我要在我的代码片段中更改什么以实现此输出?
我不在我的普通电脑上,但试试这个:
"Add a property" : {
"prefix": "prop",
"body": [
"private ;",
"public get${2:/capitalize/g}() {",
"\treturn ;",
"}",
"public void set${2:/capitalize/g}( ) {",
"\tthis. = ;",
"}"
],
"description": "Add a property to class"
}
试试这个:
"Add a property" : {
"prefix": "prop",
"body": [
"private ;",
"public get${2/(.)/${1:/capitalize}/}() {",
"\treturn ;",
"}",
"public void set${2/(.)/${1:/capitalize}/}( ) {",
"\tthis. = ;",
"}"
],
"description": "Add a property to class"
}
这部分 ${2/(.)/${1:/capitalize}/}
将转换第二个制表位。它仅捕获捕获组 1 中该单词的第一个字符 (.)
(在您的情况下为 age
),然后 ${1:/capitalize}
将大写捕获组 1 中的任何内容。
查看片段 variable transforms。
我正在使用前缀 prop
生成:
private ;
public void set( ) {
this. = ;
}
public get() {
return ;
}
这是我的代码片段:
"Add a property" : {
"prefix": "prop",
"body": [
"private ;",
"public get() {",
"\treturn ;",
"}",
"public void set( ) {",
"\tthis. = ;",
"}"
],
"description": "Add a property to class"
}
输出:
private int age;
public int getage() {
return age;
}
public void setage(int age) {
this.age = age;
}
预期输出:
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
我要在我的代码片段中更改什么以实现此输出?
我不在我的普通电脑上,但试试这个:
"Add a property" : {
"prefix": "prop",
"body": [
"private ;",
"public get${2:/capitalize/g}() {",
"\treturn ;",
"}",
"public void set${2:/capitalize/g}( ) {",
"\tthis. = ;",
"}"
],
"description": "Add a property to class"
}
试试这个:
"Add a property" : {
"prefix": "prop",
"body": [
"private ;",
"public get${2/(.)/${1:/capitalize}/}() {",
"\treturn ;",
"}",
"public void set${2/(.)/${1:/capitalize}/}( ) {",
"\tthis. = ;",
"}"
],
"description": "Add a property to class"
}
这部分 ${2/(.)/${1:/capitalize}/}
将转换第二个制表位。它仅捕获捕获组 1 中该单词的第一个字符 (.)
(在您的情况下为 age
),然后 ${1:/capitalize}
将大写捕获组 1 中的任何内容。
查看片段 variable transforms。