【问题标题】:How to add snippet to Visual Studio Code for multiple languages?如何为多种语言向 Visual Studio Code 添加代码段?
【发布时间】:2017-11-28 15:09:25
【问题描述】:

我有几个在jsjsxhtml 文件之间共享的sn-ps。现在我在 3 个文件中有相同的 sn-p 代码。是否可以创建 sn-p 并指定它应该适用于哪些文件/类型?

【问题讨论】:

标签: visual-studio-code code-snippets


【解决方案1】:

点击cmd + p 访问命令栏,然后输入“sn-ps”并选择Preferences: Configure User Snippets,然后选择New Global Snippets file。为文件命名后,它将创建一个全局 sn-ps 文件,您可以在其中定义可以使用 scope 属性中定义的任何语言访问的 sn-ps。

"Div Tag": {
  "scope": "javascript,javascriptreact,html",
  "prefix": "div",
  "body": "<div>$1</div>",
  "description": "Create a div tag"
}

更新

使用正确的语言标识符修复范围属性以响应 cmets。

【讨论】:

  • 文件终止 js,jsx 在我的情况下不起作用。相反,我使用"scope": "javascript,javascriptreact" 让 sn-ps 在 .js 和 .jsx 文件中工作。检查这个答案:stackoverflow.com/a/55653650/8182578
猜你喜欢
  • 2017-04-17
  • 2020-12-27
  • 1970-01-01
  • 2016-08-07
  • 1970-01-01
  • 1970-01-01
  • 2017-05-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多