Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 1.69 KB

2 代码片段.md

File metadata and controls

64 lines (54 loc) · 1.69 KB

2代码片段

参考vscode官方文档

1 内置片段

2 扩展片段

  • 扩展插件中包含对应语言的代码片段

3 自定义片段

{
  "hello world": {
    "prefix": "hello",
    "body": [
      "#include <iostream>",
      "#include <vector>",
      "using namespace std;",
      "int main()",
      "{",
      "\tvector<int> vec;",
      "\t${1:elemet}",
      "\tcout<<endl;",
      "\treturn 0;",
      "}"
    ],
    "description": "start a cpp"
  }
}
  • prefix:触发代码片段的前缀
  • body:代码片段的内容
  • description:描述
  • 占位符是带有值的制表符,例如${1:foo}。占位符文本将被插入和选择,以便可以轻松更改。占位符可以嵌套,例如${1:another ${2:placeholder}}

4 语法表达式

any         ::= tabstop | placeholder | choice | variable | text
tabstop     ::= '$' int
                | '${' int '}'
                | '${' int  transform '}'
placeholder ::= '${' int ':' any '}'
choice      ::= '${' int '|' text (',' text)* '|}'
variable    ::= '$' var | '${' var '}'
                | '${' var ':' any '}'
                | '${' var transform '}'
transform   ::= '/' regex '/' (format | text)+ '/' options
format      ::= '$' int | '${' int '}'
                | '${' int ':' '/upcase' | '/downcase' | '/capitalize' | '/pascalcase' '}'
                | '${' int ':+' if '}'
                | '${' int ':?' if ':' else '}'
                | '${' int ':-' else '}' | '${' int ':' else '}'
regex       ::= JavaScript Regular Expression value (ctor-string)
options     ::= JavaScript Regular Expression option (ctor-options)
var         ::= [_a-zA-Z] [_a-zA-Z0-9]*
int         ::= [0-9]+
text        ::= .*