Snippet Generatorという拡張機能を使用すると簡単にスニペットを作成できます。
スニペットを作成したいコードを選択してコマンドパレットからGenerate Snippet
を実行し、必要事項を入力するとスニペットを設定するためのオブジェクトがクリップボードに保存されます。
Snippets Configure User Snippets
を実行します。
開いた設定ファイルにクリップボードの内容を貼り付けるとスニペットを使用できるようになります。
以下のようにショートカットキーを設定するとGenerate Snippet
の必要事項を入力した後にSnippets Configure User Snippets
が実行されファイル選択できるようになり、より簡単に作成できます。
keybindings.json
{
{
"key": "任意のキー",
"command": "runCommands",
"args": {
"commands": [
"snippet-generator.generate-snippet",
"workbench.action.openSnippets"
]
}
}
}