vscode设置代码段

1. 打开编辑器>文件>首选项>用户代码片段>输入要创建的代码类型>会生成一个json文件

在这里插入图片描述

2. 按语法编写

prefix      :代码片段名字,即输入此名字就可以调用代码片段。
body        :这个是代码段的主体.需要编写的代码放在这里,      
$1          :生成代码后光标的初始位置.
$2          :生成代码后光标的第二个位置,按tab键可进行快速切换,还可以有$3,$4,$5.....
${1,字符}    :生成代码后光标的初始位置(其中1表示光标开始的序号,字符表示生成代码后光标会直接选中字符。)
description :代码段描述,输入名字后编辑器显示的提示信息。

我的示例:

{
	// Place your snippets for javascript 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"
	// }
	"rrn": {
		"prefix": "rrn",
		"body": [
			"import React,{Component} from 'react'",
			"import {View,Text} from 'react-native'",
			"class Index extends Component {",
			"\trender(){",
			"\t\treturn (",
			"\t\t\t<View><Text></Text></View>",
			"\t\t);",
			"\t}",
			"}",
			"export default Index"
		],
		"description": "rrn"
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值