Here is an example of creating a php class code snippet:
command+shift+p
input snippet;- choose
Preferences: Configure User Snippets
; - Then type
php
Enter .
Note: Step 3 Select according to the file type of the code snippet you want to create. For example, if you want to create a java code snippet, you need to enter java. If you want to create a global code snippet that does not distinguish between file types, you need to type
glo
selectNew Globle Snippets file
and then press Enter.
At this point, the editor opens a php.json file and modifies it to the following:
{
// 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 <[email protected]>",
" * @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"
}
}
After saving, open a php file, enter the prefix, and press Enter after the shortcut prompt window myclass
appears . At this time, our custom code fragment structure has been generated. Press the tab
key in turn to switch to each preset position to change, and you can quickly create our code needed.
Basic syntax description
prefix
String prefix that triggers the quick hintbody
code snippet body$num
Each time you press thetab
key , the cursor moves to the right position, which$0
means the last position of the cursor. If it is not set$0
, the final position of the cursor is at the end of the file;${2:默认文本}
Jump to the specified position and select the default text at the same time, which is convenient for modification;$CURRENT_YEAR
is the quoted snippets built-in variable, others are:- TM_FILENAME current file name
- TM_FILENAME_BASE current filename without extension
- TM_DIRECTORY The absolute path of the directory to which the current file belongs
- TM_FILEPATH absolute path of current file
- CURRENT_YEAR Current year
- CURRENT_YEAR_SHORT Current year, last two digits
- CURRENT_MONTH Numerical form of the current month, two digits
- CURRENT_MONTH_NAME The current month in English, such as July
- CURRENT_MONTH_NAME_SHORT English abbreviation of the current month, such as Jul
- CURRENT_DATE current day
- CURRENT_DAY_NAME the current week, such as Monday
- CURRENT_DAY_NAME_SHORT Abbreviated form of the current week, such as Mon
- CURRENT_HOUR The current hour, in 24-hour format, with two digits
- CURRENT_MINUTE The current minute, two digits
- CURRENT_SECOND The current second, two digits
\n
newline\t
Tabs
description
A description of the code snippet pair in the shortcut window
For more functions, please refer to