- 打開vscode>文件>首選項(xiàng)>用戶代碼片段>新建json文件
- 或者按ctrl +shift + p 輸入 snippet 新建
{
// 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": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
},
"for of ": {
"scope": "javascript,typescript",
"prefix": "fof",
"body": [
"for(let item of $1){"
,"\t$2"
,"}"
],
"description": "快速循環(huán)數(shù)組"
}
}
(注意:創(chuàng)建哪種語言的代碼片段就進(jìn)相應(yīng)語言的代碼片段區(qū)域,寫js代碼段就不要把代碼段寫在了php的代碼段編寫區(qū))
\r\n:代表換行,填寫幾個(gè)代表換幾行,
\t:tab數(shù),有幾個(gè)代表有幾個(gè)tab