Write custom emmet snippets with higher priority than default
Asked Answered
C

3

6

How can I create custom emmet snippet with the highest possible priority to display in vscode?

When I updated html.json to add my own snippet for comment (with autor), I still see default emmet "c" snippet as first in list:

"Comment": {
    "prefix": "c",
    "body":[
        "<!-- atiris: $1 -->$2"
    ],
    "description": "Insert comment into html code"
}

That means I always have to choose the second option first.
Is there any property / settings to prioritize my own snippets?

enter image description here

Coranto answered 27/6, 2017 at 18:17 Comment(2)
Add this line in setting "editor.snippetSuggestions": "top" ;)Lovins
Don’t you think it’s strange that they generally have priority as such?? Well, if I manually entered that c > comment, then when I press tab it should be inserted, regardless of what else is there about it p.s. of course thnx and upwoted =*Basenji
C
6

This worked for me:

"editor.snippetSuggestions": "top"

Or open settings, write 'snippets' in the search box, and select 'top' in Snippet Suggestions

Settings

Colier answered 29/3, 2023 at 20:21 Comment(0)
A
1

You can use BetterSnippets vscode extension. It provides way more customization then builtin snippets. For your case you can use smth like this:

"betterSnippets.customSnippets": [
  {
    "name": "c",
    "body": "<!-- atiris: $1 -->$2",
    "when": {
        "languages": [
            "html"
        ],
    },
    "sortText": "!1"
  },
]

SortText property is what you're looking for. I use !1 to make snippets order more customizable e.g. if I would assing sortText: "!2" to other snippet it will appear under the snippet with !1

Awesome answered 6/2, 2023 at 9:54 Comment(0)
A
0

You are editing the intellisense snippets with the above code rather than the Emmet snippets.

Regarding your question, the following link may help you prioritize which snippets are shown first: https://github.com/Microsoft/vscode/issues/32346

Regarding adding snippets to Emmet, the following should help:

In the settings.json file you can add the line "emmet.extensionsPath": "/Users/username/Documents/code snippets" (changing the path to a folder of your choosing)

Then add in that folder a file named snippets.json

You can use the format outlined in the link below to add snippets. https://code.visualstudio.com/docs/editor/emmet

Adan answered 23/10, 2017 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.