Sublime Forum

I don't see my snippet description

#1

Hi, I just created a basic html5 snippet.

<snippet>
	<content><![CDATA[
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>${1}</title>
</head>
<body>
${0}
</body>
</html>
]]></content>
	<tabTrigger>html5</tabTrigger>
	<scope>text.html</scope>
	<description>HTML5 boilerplate</description>
</snippet>

My problem is that when I just create a new file cmd + N and set the syntax to HTML, and type html5. I don’t see my description or any indication of the snippet. Why is that? Have I made a mistake?

The snippet does work, when typing html5, tab results in:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>

</body>
</html>
0 Likes

#2

The auto_complete_selector setting controls in what circumstances the autocomplete popup appears as you type; the default setting for it is:

    // Controls what scopes auto complete will be triggered in
    "auto_complete_selector": "meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",

The scope for an HTML file is text.html.basic, but text doesn’t appear anywhere in the setting, so in generic parts of a text or HTML file (i.e. when the buffer is empty), the AC popup doesn’t automatically appear.

The first selector in the setting tells the AC window to appear inside of a tag, so that autocomplete will allow you to complete tags and attributes. However it doesn’t appear by default in the top level of HTML files to stop you from going slowly insane over the course of the day as the AC window is nonstop suggesting other words in the buffer for every word you type.

Regardless of whether the window appears or not, the snippet will still expand (as you noted above). You can also make it appear manually at any point by hitting Ctrl+Space (or on Linux, Alt+/) or use the Command Palette and filter the list on Snippet: to see snippets which apply to the current file, which will also show you your snippet and how to invoke it.

2 Likes

#3

Thank you so much @OdatNurd. Great explanation, very helpful.

0 Likes