Skip to main content

Snippet Insertion Features

Create dynamic snippets with tabstops, placeholders, and other snippet insertion features

How they work​

Microsoft can explain it better

Insertion Features

Add them to your snippets​

There are a few ways to add them. Your curser must be in the snippet editor.

  • Right Click while in the snippet editor and choose which feature to add
  • Use keyboard shortcuts while in the snippet editor
  • Click the three-dot menu at the right of your editor
  • Choose one of the commmands below because you love the command prompt
  • Type the name of the insertion feature and use the extension-provided snippet

Keyboard Shortcuts​

Insertion Feature Linux Mac Windows
Tabstopctrl+shift+1cmd+opt+1alt+shift+1
Placeholderctrl+shift+2cmd+opt+2alt+shift+2
Choicectrl+shift+3cmd+opt+3alt+shift+3
Variablectrl+shift+4cmd+opt+4alt+shift+4
Variable with Placeholderctrl+shift+5cmd+opt+5alt+shift+5
Placeholder with Transformationctrl+shift+6cmd+opt+6alt+shift+6
Variable with Transformationctrl+shift+7cmd+opt+7alt+shift+7

Commands​

  • Tabstops: snippetstudio.editor.insertTabStop
  • Placeholders: snippetstudio.editor.insertPlaceholder
  • Choices: snippetstudio.editor.insertChoice
  • Variables: snippetstudio.editor.insertVariable
  • Variables with Placeholders: snippetstudio.editor.insertVariablePlaceholder
  • Placeholders with Transformations: snippetstudio.editor.insertPlaceholderWithTranformation
  • Variables with Transformations: snippetstudio.editor.insertVariableWithTransformation

Examples​

Placeholders​

  • Use multiple tabstop/placeholder numbers to automatically enter mutliline editing
  • Use placeholders for default values
  • $0 is where the cursor ends after tabbing through all insertion features

Snippet Placeholder Example

Regex + Multiline​

Goal: Fast creation of a useState variable hook.

  1. Type 'state' as the prefix and hit tab to expand
  2. Type the name of the variable. ie 'myState'
  3. Hit tab to move to $2 tabstop. Regex autocapitalizes the 'M' in 'setMyState'
  4. Type a default value
  5. Hit tab to move the cursor to the end of the line
const [myState, setMyState] = useState('foo');

Solution: Use camelcase and pascalcase in Placeholder Transforms

const [${1/(.*)/${1:/camelcase}/}, set${1/(.*)/${1:/pascalcase}/}] = useState($2)$0

If you use regex you are cool. Good luck rendering that one, Docusaurus!

Variable Regex​

There's also variable transformation with regex. You can read VS Code's and TextMate's documentation if you want to better understand it.

"bullit points": {
"prefix": "bullit",
"body": [
"${TM_SELECTED_TEXT/^.+$/- $0/gm}"
],
"description": "add markdown bullets"
}

Adding bullet points