這裏以建立一個 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