这里以建立一个 php class 代码片断为例:php
command+shift+p
输入 snippet;Preferences: Configure User Snippets
;php
回车。注意:步骤 3 要根据你想建立的代码片断所属文件类型进行选择,好比你想建立 java 代码片断,就须要输入 java。若是想建立不区分文件类型的全局代码片断,须要输入
glo
选择New Globle Snippets file
以后回车。java
此时编辑器打开一个 php.json 文件,修改成如下内容:json
{ // Place your snippets for php 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: "Class File Header": { "prefix": "myclass", "body": [ "/**", " * $1", " * ", " * @author whoru.S.Q <whoru@sqiang.net>", " * @created $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND", " */", "class ${2:ClassName} ${3:extends ${4:AnotherClass}} ${5:implements ${6:Interface}}", "{", "\n\t${7:public} function ${8:methodName}($9)", "\t{", "\t\t$0", "\t}\n", "}" ], "description": "class with header" } }
保存以后,打开一个 php 文件,输入前缀 myclass
出现快捷提示窗后回车,此时已经生成了咱们自定义的代码片断结构,依次按 tab
键切换到预设的每个位置进行更改,便可快速建立咱们须要的代码。编辑器
基本语法说明.net
prefix
触发快捷提示的字符串前缀body
代码片断主体
$num
是每次按 tab
键光标移动对位置,$0
表示光标最后停留位置,不设置 $0
,这光标最终位置在文件末尾;${2:默认文本}
跳转到指定位置到同时选中默认文本,方便修改;$CURRENT_YEAR
是引用的 snippets 内置变量,其它还有:
\n
换行\t
制表符description
快捷提示窗对该代码片断对描述更多功能,请参照code