How to add common language snippets in Visual Studio Code?

后端 未结 2 1318
梦如初夏
梦如初夏 2021-02-20 14:12

In official vscode documentation i have seen that is possible to create custom snippets for each language. https://code.visualstudio.com/Docs/customization/userdefinedsnippets

2条回答
  •  忘掉有多难
    2021-02-20 15:02

    For completeness, global snippets are now supported in VS Code out the box.

    Probably redundant information as the UI already guides you to it via the auto-generated global.code-snippets file when you open User Snippets in the menu.

    However something I didn't know and landed on this answer looking to find is that you can also use the scope field to narrow global snippets to a specific subset of languages.

    For example if I want a certain snippet available in both javascript and typescript, but only in javascript and typescript (because it's annoying if it also appears in other languages)

    "My Snippet": {
      "prefix": "my-snippet",
      "body": [ "my snippet code..." ],
      "scope": "javascript,typescript" // define a strict subset of languages here
    }
    

提交回复
热议问题