如何在 vscode 中为 .npmrc 制作片段?
由于您无法将代码片段的范围限定为文件或文件扩展名,因此您可以创建一个可以将范围限定为文件扩展名的键绑定。在你的
keybindings.json
:
{
"key": "alt+t",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && (resourceExtname =~ /\\.npmrc/ || resourceFilename =~ /(\\.npmrc)/)",
"args": {
"snippet": "registry=https://registry.npmmirror.com"
}
}
这适用于
.npmrc
和 xxxx.npmrc
文件。
因为在您的情况下,您没有使用任何片段功能,您可以简单地使用:
{
"key": "alt+t",
"command": "type",
"when": "editorTextFocus && (resourceExtname =~ /\\.npmrc/ || resourceFilename =~ /(\\.npmrc)/)",
"args": {
"text": "registry=https://registry.npmmirror.com"
}
}