18

I was just trying to make some snippets but I can't get any of them to work. Can anyone see what's wrong with this? I read their docs and thumbed some examples off the web but they don't work either. I've got it in my /sublime text 3/packages/user folder and it's named using convention myTest.sublime.snippet.

The snippet is:

<snippet>
    <content>
<![CDATA[
<!DOCTYPE html lang="en">
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <title>${1:test1|test2|test3} | $2</title>
    <meta name="viewport" content="width=device-width">
    <meta name="Description" lang="en" content="Description">
    <meta name="robots" content="index, follow">
    <meta name="robots" content="noodp, noydir">

    <!-- Twitter Bootstrap -->
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet">
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <script src="assets/js/respond.min.js"></script>
    <![endif]-->    
</head>
<body>

    <div class="container">
        $3
    </div>

</body>
</html>
]]>
</content>
    <tabTrigger>page</tabTrigger>
    <scope>source.html</scope>
    <description>HTML5 Base HTML</description>
</snippet>
4
  • 13
    The naming convention is *.sublime-snippet. Try fixing that first, unless it was a typo in your question. If it still doesn't work, run the show_scope_name command on a file, what scopes appear? I don't know all of the key bindings for this command, you can either look for it or enter view.run_command("show_scope_name") in the ST console. Commented Sep 15, 2013 at 19:50
  • Wow, embarrassing! It was just missing the dash, thanks for the help! Not sure how to mark this as the best answer. Thanks for all the help Skuroda and Soon. Cheers!!! Commented Sep 15, 2013 at 20:51
  • See the scope first using following command. view.scope_name(view.sel()[0].begin()) in sublime console. To bring up sublime console type Ctrl+` in MacOs Commented Dec 1, 2016 at 22:02
  • When I send the command view.scope_name(view.sel()[0].begin()) in the console,it returns text.xml meta.tag.xml punctuation.definition.tag.end.closing.xml . In my snippet, the scope is set as <scope>text.md</scope>. Have I set the scope incorrectly? Commented Jan 10, 2024 at 8:34

9 Answers 9

13

You should use text.html instead of source.html in scope block.

Sign up to request clarification or add additional context in comments.

4 Comments

Hey, thanks for the reply. I replaced source.html with text.html and it still doesn't show the snippet when I tab after typing page :(
Try to make a folder named HTML in Packages/User and place snippet into it.
Yah, still doesn't work. I can't even hit "New Snippet" and get the hello world example to work with me just uncommenting the bottom tags, but all the built in ones work just fine.
Strangely. I copy-pasted your example into HTML folder, change source to text and the snippet works. Try to unzip the default HTML.sublime-package, change something in snippet, place it in User or User/HTML folder and try to call. Also try to restart ST3.
13

Sublime 3 needs snippets to have .sublime-snippet endings in file name.

Comments

8

Step1. For html snippet, please change

<scope>source.html</scope>

to

<scope>text.html</scope>

Step2. If you want sublime to show tooltips after you input the keywords, add this line

"auto_complete_selector": true

to your Preferences - Settings User file

Comments

7

You should escape dollar signs in your snippet. $ -> \$.

Comments

6

I had the same problem and what I did was :

Just remove <scope>source.html</scope> line present at the bottom of the snippet.

Comments

3

Remove:

<description>HTML5 Base HTML</description>

Yes, this line comes from the official documentation, but at least in my instance (Sublime 3, Build 3114), it breaks the snippet. When I remove that line, the snippet works.

Also, as Jinglong above answered, add the following to your user preferences:

"auto_complete_selector": true

Comments

2

This is clearly an old thread, but it came up when I was searching on creating sublime snippets. The initial issue might be that you are typing in "page" as your tab trigger without first setting your syntax to html. You can do this quickly with shift + command/control + p then type sshtml then enter. Try your tab trigger again. Worked for me. Cheers.

Comments

2

solved by..

  • removing <scope>source.html</scope>
  • adding "auto_complete_selector": true, to user settings

Background

My js/ snippets worked fine with <scope>source.html</scope> but for whatever reason, that line caused issues in my html/ snippets not.

1 Comment

So, just be sure not to follow the official documentation, and you'll be fine! I removed both <scope> and <description> and my snippet worked. (I didn't have to set the scope either.) I had to restart ST for it to show up in the snippets toolbar.
0

I found the solution to my problem! I have been using the unicode setting for my keyboard for another project. When I changed my keyboard back to US, my problem was resolved. I'm sure this is an unusual issue, but in case anyone else is having this problem:

changing the keyboard back to US also reactivated some of the code navigation shortcuts (e.g., jumping word-to-word on a line by holding down option + arrow keys)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.