为什么这个 vscode 用户片段添加了一个额外的换行符?
Why is this vscode user snippet adding an extra newline?
片段:
"Create a field with getter and setter" : {
"prefix": "prop",
"body": [
"private ${2:type} ${3:var_name} = ${4:val};",
"\n",
"public void set_${3:var_name}(${2:type} ${3:var_name}) {",
"\tthis.${3:var_name} = ${3:var_name};",
"}",
"\n",
"public ${2:type} get_${3:var_name}() {",
"\treturn ${3:var_name};",
"}"
]
}
结果:
private type var_name = val;
public void set_var_name(type var_name) {
this.var_name = var_name;
}
public type get_var_name() {
return var_name;
}
预期输出:
private type var_name = val;
public void set_var_name(type var_name) {
this.var_name = var_name;
}
public type get_var_name() {
return var_name;
}
如上所示,在 \n
之后添加了一个额外的换行符。我是新手,这是我的第一个用户定义的片段。我到底错过了什么?
每行自动换行。当您有 "\n"
时,您将发送一个换行符,然后是一个换行符。如果你想要单个空行,只需使用 ""
片段:
"Create a field with getter and setter" : {
"prefix": "prop",
"body": [
"private ${2:type} ${3:var_name} = ${4:val};",
"\n",
"public void set_${3:var_name}(${2:type} ${3:var_name}) {",
"\tthis.${3:var_name} = ${3:var_name};",
"}",
"\n",
"public ${2:type} get_${3:var_name}() {",
"\treturn ${3:var_name};",
"}"
]
}
结果:
private type var_name = val;
public void set_var_name(type var_name) {
this.var_name = var_name;
}
public type get_var_name() {
return var_name;
}
预期输出:
private type var_name = val;
public void set_var_name(type var_name) {
this.var_name = var_name;
}
public type get_var_name() {
return var_name;
}
如上所示,在 \n
之后添加了一个额外的换行符。我是新手,这是我的第一个用户定义的片段。我到底错过了什么?
每行自动换行。当您有 "\n"
时,您将发送一个换行符,然后是一个换行符。如果你想要单个空行,只需使用 ""