Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add snippet to Visual Studio Code for multiple languages?

I have couple of snippets that shared between js, jsx and html files. Now I have the same snippet code in 3 files. Is it possible to create snippet and specify to what files/types it should be applicable?

like image 491
Alex G.P. Avatar asked Nov 28 '17 15:11

Alex G.P.


1 Answers

Hit cmd + p to access the command bar, then type 'snippets' and select Preferences: Configure User Snippets, then New Global Snippets file. Once you name your file, it will create a global snippets file where you can define snippets that are accessible in any language defined on the scope property.

"Div Tag": {
  "scope": "javascript,javascriptreact,html",
  "prefix": "div",
  "body": "<div>$1</div>",
  "description": "Create a div tag"
}

UPDATE

Fixed the scope property with the correct language identifiers in response to the comments.

like image 52
Christian Jensen Avatar answered Oct 28 '22 07:10

Christian Jensen