I couldn't find anybody asking how to do this: if I'm using typescript, I may want a keyboard shortcut for generating the boilerplate of an "if statement" like so:
if (/* cursor starts here */) {
/* selected text goes here */
}
But if I'm using another language, like Python, I would want a different "if statement":
if /* cursor starts here */:
/* selected text goes here */
The official documentation explains how to map a single keyboard shortcut to a single snippet. But as far as I could tell, it doesn't explain how to map a single keyboard shortcut to multiple snippets (each in a separate language file).
It felt like the documentation left enough clues to figure this out on my own:
{
"key": "cmd+k 1",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"langId": "csharp",
"name": "myFavSnippet"
}
}
I assumed this would be as easy as copying and pasting that in the keyboard shortcuts bindings file, and modifying the langId
and name
where appropriate. But this just seemed to call the snippet of the last matching entry in the file.
So, how do I assign a single shortcut to multiple snippets, depending on what language file I'm typing in?