vscode配置用户代码片段
vscode IDE 提供用户自定义设置开发模板,能够快速实现文件的基础结构,省去手敲的时间
配置
方法一

方法二
cmd + shift + p 调出全局命令控制
搜索 snippet
配置功能入口

template基本格式
{
// 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"
// }
"Print to vueSetup": {
"prefix": "vueSetup",
"body": [
"<template>",
"<div class='custom-wrapper'>$1</div>",
"</template>\n",
"<script lang='ts' setup>\n",
"</script>\n",
"<style lang='less' scroped>\n",
"</style>\n"
]
}
}
参数释义
- prefix :这个参数是使用代码段的快捷方式入口,比如这里的log在使用时输入log会有智能感知并且显示body里面的代码段.
- body :这个是代码段的主体.需要设置的代码放在这里
- $1 :这个为光标的所在位置.
- $2 :使用这个参数后会光标的下一位置将会另起一行,按tab键可进行快速切换,还可以有$3,$4,$5…
测试实例
vueSetup

