Home > Net >  User Snippets for Svelte in VSCode
User Snippets for Svelte in VSCode

Time:01-21

I struggle to create a simple snippet for .svelte files or Svelte project. Here's the procedure i've tried:

  1. Ctrl Maj P to open "Preference: Configure user Snippets"
  2. New Global Snippets File ... typed svelte to create the svelte.json file
  3. Inside of it the below code
{
  "test": {
    "scope": "Svelte",
    "prefix": "xx",
    "body": ["This is a simple test"],
    "description": "Code snippet for testing"
  }
}

Any idea ?

CodePudding user response:

The scope id for Svelte is probably svelte lowercase. If you click on the Svelte language id button in the lower right when you have a .svelte file open, you can look through those language ids for svelte - the correct version to use is that in the parentheses like

Svelte (svelte) use the version in parentheses - svelte lowercased

{
  "test": {
    "scope": "svelte",
    "prefix": "xx",
    "body": ["This is a simple test"],
    "description": "Code snippet for testing"
  }
}

Works fine in a .svelte file.

You do not need to remove the scope selector but it is redundant if it is already inside the svelte.json file which limits all snippets within it to that filetype.

  •  Tags:  
  • Related