我使用具有绑定功能的javascript代码段。
我在下面有此代码:
{
"key": "alt+c",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": " const $TM_CURRENT_WORD = $1"
}
},
如果我键入box
,然后按alt + c,我得到...
box const box =
但是我期望
const box =
我该如何实现?
box
文本,然后选择alt + c,您将得到结果。但是需要额外的选择步骤。
使用像multi-command这样的宏扩展名,将其放入您的settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.insertConst", // whatever name you want to give it
"sequence": [
"cursorWordLeftSelect",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "const $TM_SELECTED_TEXT = $1"
}
}
]
}
]
和一些绑定:
{ "key": "alt+c", "command": "multiCommand.insertConst", // use same name here "when": "editorTextFocus", }
,然后键入其值,如下所示:
或者您可以只修改代码段,这样您就不必先输入变量名。您将触发代码段,然后键入变量名称tab
{
"key": "alt+c",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": " const $1 = $2"
}
},