Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the snippets location in Visual Studio Code

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.

like image 435
user2707674 Avatar asked Feb 07 '17 15:02

user2707674


2 Answers

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
like image 66
Gama11 Avatar answered Oct 27 '22 20:10

Gama11


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

like image 35
Mark Avatar answered Oct 27 '22 20:10

Mark