vscode如何自定义补全内容,自定义常用的快捷方式?
step1:
vscode中按ctrl+shift+p
,然后输入snippet,点击这个:
选择对应的语言,随后出现.json
文件,这里以go语言为例:
step2:加入自己设定的快捷方式
这段英文其实已经告诉你怎么定义了,不懂的可以看我的示例:
{
// Place your snippets for go here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
//这是我自己定义的快捷方式
"pln":{
"prefix": "pln",//输入"pln"时
"body": "fmt.Println($0)",//自动补全"fmt.Println($0)"
"description": "fmt.Println()"//描述,随便写
},
"plf":{
"prefix": "plf",//输入"plf"时
"body": "fmt.Printf($0)",//自动补全"fmt.Printf($0)"
"description": "fmt.Printf()"//描述,随便写
}
}
step3:当我在编辑器中输入pln
时:会自动弹出
然后回车即可:
若想一个名字的快捷方式有多个补全的可能,在.json
文件中定义多个快捷方式(同prefix不同body)即可