Change the snippets location in Visual Studio Code

这一生的挚爱 提交于 2019-12-05 14:55:57

Update: project level snippets are now a built-in feature as of the September 2018 release, so this no longer requires a third-party extension.


There is currently an open feature request for this (#8102), but you can already get this functionality by using the Project Snippets extension - it lets you place snippets in:

.vscode/snippets/<language>.json

[added as an answer because really too long for a comment, just adding the details from the updated link in @Gama11's answer above.]

Per the September 2018 update mentioned above:

Ctrl-Shift-P, choose "Preferences: Configure User Snippets",

then you should see an option like: "New Snippets for [your workspaceFolder name here]…" Choose that and it will create a global snippets file in the .vscode folder.

So as long as you have that folder under source control you are set. Although it is a global snippets file, you can limit the scope of each snippet like so:

{
  "prefix": myPrefix,
  "body": "...",
  "description": "some description",
  "scope": "javascript,typescript"
}

Now those scoped snippet prefixes will not show (as suggestions) in all file types.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!