我不认为你可以按照你展示的方式做到这一点,但是通过任务来做到这一点非常容易。在你的tasks.json中:
{
"version": "2.0.0",
"tasks": [
{
"label": "new react folder and files",
"command": "mkdir ${input:dirName} && touch '${input:dirName}/${input:dirName}.component.jsx' '${input:dirName}/${input:dirName}.styles.jsx'",
"type": "shell",
"problemMatcher": [],
"presentation": {
"echo": false,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
}
],
// ........................................................................................
"inputs": [
{
"type": "promptString",
"id": "dirName",
"description": "Complete my folder name",
"default": "jsx folder to create"
}
]
}
以及一些触发任务的键绑定(在您的 keybindings.json 中):
[
{
"key": "alt+j",
"command": "workbench.action.tasks.runTask",
"args": "new react folder and files",
}
]
这将提示输入目录名称,然后在其中创建文件夹和两个文件。
[我使用了 bash 命令mkdir
and touch
创建文件夹和文件,如果您使用的 shell 没有这些命令,请交换您拥有的命令。]