如何在 vscode 中为 .npmrc 制作片段?

问题描述 投票:0回答:1

如何在 vscode 中为 .npmrc 制作片段?

visual-studio-code code-snippets vscode-snippets
1个回答
0
投票

由于您无法将代码片段的范围限定为文件或文件扩展名,因此您可以创建一个可以将范围限定为文件扩展名的键绑定。在你的

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"
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.