vscode自定义代码提示

  • Post author:
  • Post category:其他


  1. 点击vscode左下角齿轮图标 -设置
  2. 依次点击 设置-用户代码片段-新代码片段
  3. 提示输入文件名,文件拓展名是x,起名为x.json (例如想在vue中新增,就取名vue.json)
  4. 此时创建好的文件拓展名为code-snippets,需要右键单击文件找到文件位置,更改为vue.json(此为举例,具体名字依赖于你文件的拓展名)
  5. 更改完成后会出现
{
	// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. 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": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
}
  1. 在大括号内部加入所需代码(举了一个例子)
"js": { // 片段名称(想起什么什么)
		"prefix": "scr1", // 输入触发联想提升
		"body": [ // 确认后添加的代码
			"script type=\"text/javascript\" src=\"$1\"></script>",//添加的内容
		],
		"description": "" // 提示的内容
	}
保存即可  ,输入<scr1提示<script type="text/javascript" src=""></script>"



版权声明:本文为qq_45686860原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。