⇠ chan.dev / posts

Create Workspace Snippets in VS Code

🌱 This post is in the growth phase. It may still be useful as it grows up.


Using variables


Surround in snippet

VS Code provides variables for snippets. TM_SELECTED_TEXT places your selected text in the snippet.

To utilize this variable, you can’t rely on autocomplete (because typing would delete your selection).

Open the [Command Palette][https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette]. Select Snippets: Surround with Snippet…. And select the snippet you’d like to use.

Alternatively, establish a keyboard shortcut for editor.action.showSnippets when editorTextFocus.

"key": "ctrl+alt+s",
"command": "editor.action.showSnippets",
"when": "editorTextFocus"


Other notes