/ 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][]. 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

  • I think that if you want to have language specific project files, you have to build them up as extensions.