How to add common language snippets in Visual Studio Code?

后端 未结 2 1363
梦如初夏
梦如初夏 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 14:54

    Common users snippets are currently not supported, but there is a VSCode issue tracking this feature request. Please let us know if this is something you would find useful.


    For completeness, VSCode extensions can register the same snippets for multiple languages but they must explicitly specify all languages they provide snippets for (there is no "language": "*" option).

    0 讨论(0)
  • 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
    }
    
    0 讨论(0)
提交回复
热议问题