Change the snippets location in Visual Studio Code

匆匆过客 提交于 2019-12-07 11:19:37

问题


I am using visual studio code, and need to place the user snippets in my project repository. How can I change the location of the snippets file to a custom one? I am working on windows 10.


回答1:


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



回答2:


[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.



来源:https://stackoverflow.com/questions/42094206/change-the-snippets-location-in-visual-studio-code

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