Change the snippets location in Visual Studio Code
Asked Answered
O

2

9

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.

Ouzo answered 7/2, 2017 at 15:51 Comment(0)
V
11

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
Vanhoose answered 7/2, 2017 at 16:9 Comment(1)
Is there also a way to change the base path of the user snippets system wide, not porject wise?Divinity
E
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.

Eohippus answered 9/11, 2018 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.