更加详细的可以阅读这里: 你可以看到when的具体范围解释,非常详细。。这里我就不一一列举出来了。。。直接在链接的文章内搜索when Clause Contexts
进入代码片段自定义有两种方式: \1. 【菜单栏->文件->首选项->用户代码片段】 \2. 全局命令【ctrl+shift + p => snippet】
VSCODE的代码片段支持30多种编程语言,所以也免了代码片命名唯一和全局生效【所有文件】的尴尬
这里就选择一个sass的说下,内部有这么一段注释嗯
{
/*
// Place your snippets for Sass 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, ${id} and ${id:label} and ${1:label} for variables. Variables with the same id are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
*/
"utf-8": {
"prefix": "utf-8",
"body": [
"@charset 'UTF-8';"
],
"description": "插入文件编码"
},
"impout": {
"prefix": "impcfg",
"body": [
"@import '../../../assets/scss_styles/custom_scss/_custom-export.scss';"
],
"description": "插入配置文件"
},
"toRem": {
"prefix": "rem",
"body": [
"toRem($0)"
],
"description": "插入px转换函数"
},
"removeDedault": {
"prefix": "ra",
"body": [
"@include remove-a-default-behavior"
],
"description": "移除a的下划线"
}
}
-
toRem
: 只是一个单纯的描述 -
prefix
: 是触发snippet的简写 -
body: 是展开的代码片段
-
1,2表示占位符,用于用户展开代码片段所需要替换的,也可以写成
${1:label}
键值对的方式 -
description
: 用户你在输出snippet之前,方便自己识别的注释,而不用强行记忆那些简写的