首页 > 解决方案 > 如何在 VSCode 中添加自定义 emmet 片段?

问题描述

根据2020 年 10 月的变更日志,可以为 VSCode 添加自定义代码段。假设我已经snippets.json找到了workspace\configs\emmet这样的内容:

{
  "html": {
    "snippets": {
      "btn:b|button:button|button:b": "button[type={button}] ${1}"
    }
  }
}

我想以.code-workpace文件操作系统无关的方式链接它的路径,所以使用一堆VSCode 变量

{
  "settings": {
    "emmet.extensionsPath": "${workspaceFolder}${pathSeparator}configs${pathSeparator}emmet"
  }
}

但是这个新片段没有出现在建议中。是什么赋予了?

标签: htmlvisual-studio-codejsxvscode-settingsemmet

解决方案


在 VS 代码菜单中,点击 File -> Preferences -> User Snippets,

然后像这样添加代码段:

"<snippets name>": {
        "scope":  "< e.g javascript,typescript,vue,coffeescript,typescriptreact>",
        "prefix": "<your prefix>",
        "body": [
                "<snippet body"
        ]
},

推荐阅读