With $name or ${name:default}, you can insert the value of a variable. When a variable isn't set, its default or the empty string is inserted. When a variable is unknown (that is, its name isn't defined) the name of the variable is inserted and it is transformed into a placeholder.
The following variables can be used:
-
TM_SELECTED_TEXTThe currently selected text or the empty string -
TM_CURRENT_LINEThe contents of the current line -
TM_CURRENT_WORDThe contents of the word under cursor or the empty string -
TM_LINE_INDEXThe zero-index based line number -
TM_LINE_NUMBERThe one-index based line number -
TM_FILENAMEThe filename of the current document -
TM_FILENAME_BASEThe filename of the current document without its extensions -
TM_DIRECTORYThe directory of the current document -
TM_FILEPATHThe full file path of the current document -
CLIPBOARDThe contents of your clipboard -
WORKSPACE_NAMEThe name of the opened workspace or folder
For inserting the current date and time:
-
CURRENT_YEARThe current year -
CURRENT_YEAR_SHORTThe current year's last two digits -
CURRENT_MONTHThe month as two digits (example '02')
*CURRENT_MONTH_NAMEThe full name of the month (example 'July')
*CURRENT_MONTH_NAME_SHORTThe short name of the month (example 'Jul') -
CURRENT_DATEThe day of the month -
CURRENT_DAY_NAMEThe name of day (example 'Monday') -
CURRENT_DAY_NAME_SHORTThe short name of the day (example 'Mon') -
CURRENT_HOURThe current hour in 24-hour clock format -
CURRENT_MINUTEThe current minute -
CURRENT_SECONDThe current second -
CURRENT_SECONDS_UNIXThe number of seconds since the Unix epoch
For inserting line or block comments, honoring the current language:
-
LINE_COMMENTExample output: in PHP//
The snippet below inserts /* Hello World */ in JavaScript files and
<!-- Hello World -->
in HTML files:
{
"hello": {
"scope": "javascript,html",
"prefix": "hello",
"body": "$BLOCK_COMMENT_START Hello World $BLOCK_COMMENT_END"
}
}
More-->https://code.visualstudio.com/docs/editor/userdefinedsnippets












网友评论