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)即可

posted @ 2020-11-04 21:44  Luweir  阅读(358)  评论(0编辑  收藏  举报