Visual Studio Code(VS Code) 自定义代码块

先点击屏幕左下角的齿轮图标按钮,然后点击User Snippets

选择新建一个代码块文件,当然也可以使用默认的。

输入文件名称,输入完成后按下回车键就可以新建了,以后还需要修改代码块就直接搜索名称即可,需要重新新建。

这个样子就是新建成功了

这一段英文大概得意思是,将全局代码片段放在这里。每个代码段在代码段名称下定义,并具有作用域、前缀、主体和描述。在scope字段中添加以逗号分隔的代码片段适用的语言id。如果范围为空或省略,则该代码段将应用于所有语言。前缀是什么用于触发代码片段,然后展开并插入代码体。可能的变量有: $1, $2表示制表符,$0表示光标的最终位置,${1:label}, ${2:another}表示占位符。连接具有相同id的占位符。

这里我补充一下几个字段的意思

scope : 此代码段使用的语言名称列表,例如 "typescript,javascript"。

 prefix : 在 Intellisense 中选择代码片段时要使用的前缀 

body :片段内容。

 description : 代码片段描述。

下满写入自己的代码块这里给大家分析一个 代码块底代码生成工具 

{
	// Place your global 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": "clog",
		"body": [
			"console.log('$1');",
			"$2"
		],
		"description": "Log output to console"
	},
	"vue code": {
		"prefix": "vue template",
		"body": [
			"<template>",
			"\t<div>",
			" ",
			"\t</div>",
			"</template>",
			"<script>",
			"export default {",
			"\tname:'',",
			"\tcomponents: {",
			" ",
			"\t},",
			"\tdata() {",
			"\t\treturn {",
			" ",
			"\t\t}",
			"\t},",
			"\tcreated() {",
			"",
			"\t},",
			"\tmethods: {",
			" ",
			"\t},",
			"}",
			"</script>",
			"<style lang=\"scss\" scoped>",
			" ",
			"</style>"
		],
		"description": "vue2 basic module"
	}
}

注册完成后就可以去试试了

这样一个全局代码块就弄好啦

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值