'editor.tabCompletion': 'on'
, type a snippet prefix (trigger text), and press Tab to insert a snippet.u
; both are not supported.for
loop snippet for JavaScript:description
is provided.prefix
defines one or more trigger words that display the snippet in IntelliSense. Substring matching is performed on prefixes, so in this case, 'fc' could match 'for-const'.body
is one or more lines of content, which will be joined as multiple lines upon insertion. Newlines and embedded tabs will be formatted according to the context in which the snippet is inserted.description
is an optional description of the snippet displayed by IntelliSense.body
of the example above has three placeholders (listed in order of traversal): ${1:array}
, ${2:element}
, and $0
. You can quickly jump to the next placeholder with Tab, at which point you may edit the placeholder or jump again the next one. The string after the colon (if any) is the default text, for example element
in ${2:element}
. Placeholder traversal order is ascending by number, starting from one; zero is an optional special case that always comes last, and exits snippet mode with the cursor at the specified position.javascript.json
), which you can access by language identifier through Preferences: Configure User Snippets. A snippet is only accessible when editing the language for which it is defined..code-snippets
), which is also accessible through Preferences: Configure User Snippets. In a global snippets file, a snippet definition may have an additional scope
property that takes one or more language identifiers, which makes the snippet available only for those specified languages. If no scope
property is given, then the global snippet is available in all languages..code-snippets
) scoped to your project. Project-folder snippets are created with the New Snippets file for '.vscode
folder. Project snippet files are useful for sharing snippets with all users working in that project. Project-folder snippets are similar to global snippets and can be scoped to specific languages through the scope
property.body
of a snippet can use special constructs to control cursors and the text being inserted. The following are supported features and their syntaxes:$1
, $2
to specify cursor locations. The number is the order in which tabstops will be visited, whereas $0
denotes the final cursor position. Multiple occurrences of the same tabstop are linked and updated in sync.${1:foo}
. The placeholder text will be inserted and selected such that it can be easily changed. Placeholders can be nested, like ${1:another ${2:placeholder}}
.${1|one,two,three|}
. When the snippet is inserted and the placeholder selected, choices will prompt the user to pick one of the values.$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.TM_SELECTED_TEXT
The currently selected text or the empty stringTM_CURRENT_LINE
The contents of the current lineTM_CURRENT_WORD
The contents of the word under cursor or the empty stringTM_LINE_INDEX
The zero-index based line numberTM_LINE_NUMBER
The one-index based line numberTM_FILENAME
The filename of the current documentTM_FILENAME_BASE
The filename of the current document without its extensionsTM_DIRECTORY
The directory of the current documentTM_FILEPATH
The full file path of the current documentCLIPBOARD
The contents of your clipboardWORKSPACE_NAME
The name of the opened workspace or folderCURRENT_YEAR
The current yearCURRENT_YEAR_SHORT
The current year's last two digitsCURRENT_MONTH
The month as two digits (example '02')CURRENT_MONTH_NAME
The full name of the month (example 'July')CURRENT_MONTH_NAME_SHORT
The short name of the month (example 'Jul')CURRENT_DATE
The day of the monthCURRENT_DAY_NAME
The name of day (example 'Monday')CURRENT_DAY_NAME_SHORT
The short name of the day (example 'Mon')CURRENT_HOUR
The current hour in 24-hour clock formatCURRENT_MINUTE
The current minuteCURRENT_SECOND
The current secondCURRENT_SECONDS_UNIX
The number of seconds since the Unix epochBLOCK_COMMENT_START
Example output: in PHP /*
or in HTML <!--
BLOCK_COMMENT_END
Example output: in PHP */
or in HTML -->
LINE_COMMENT
Example output: in PHP //
/* Hello World */
in JavaScript files and <!-- Hello World -->
in HTML files:foo.txt
it makes foo
.example-123.456-TEST.js
.Example | Output | Explanation |
---|---|---|
'${TM_FILENAME/[.]/_/}' | example-123_456-TEST.js | Replace the first . with _ |
'${TM_FILENAME/[.-]/_/g}' | example_123_456_TEST_js | Replace each . or - with _ |
'${TM_FILENAME/(.*)/${1:/upcase}/}' | EXAMPLE-123.456-TEST.JS | Change to all uppercase |
'${TM_FILENAME/[^0-9^a-z]//gi}' | example123456TESTjs | Remove non-alphanumeric characters |
(backslash), you can escape $
, }
, and
. Within choice elements, the backslash also escapes comma and pipe characters.keybindings.json
(Preferences: Open Keyboard Shortcuts File), which defines all your keybindings, and add a keybinding passing 'snippet'
as an extra argument:snippet
argument value to define your snippet inline, you can reference an existing snippet by using the langId
and name
arguments. The langId
argument is the name of the JSON user snippet file and name
is the snippet's unique name from this file: