4

I have just written the following snippet, and saved it in the folder Packages/User/HTML as "add-script-source.sublime-snippet."

<snippet>
    <content><![CDATA[
<script type="text/javascript" src="${1:script.js}">${2}</script>
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>scriptsrc</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html</scope>
</snippet>

Now, I only want this snippet to work in HTML files, but it does not. If I comment out the "scope" tag, it will work in JavaScript, but still not in HTML. I was under the impression that the name of the folder beneath your User folder also gave Sublime Text the appropriate scope (as stated in this video https://tutsplus.com/lesson/your-first-snippet/), this does not appear to do anything. Whenever I set the scope tag to ANYTHING, the snippet does not trigger.

What might the problem be?

3
  • 1
    Your snippet works fine for me. Are you sure you are setting the file to HTML in the bottom right corner of ST2? Commented Oct 21, 2013 at 13:25
  • Maybe you have a conflict with another package. Try disabling any HTML related package (such as Zen coding) and see what happens. Commented Oct 21, 2013 at 15:12
  • Okay, it appears as though it IS working, just the helpful sublime text autocomplete doesn't appear, as it does in other languages. Does anyone know why this might be? Commented Oct 21, 2013 at 19:33

1 Answer 1

19

"just the helpful sublime text autocomplete doesn't appear, as it does in other languages. Does anyone know why this might be?"

You need to add this to your Packages/User/Preferences.sublime-settings file.

 "auto_complete_selector": "source, text"

Then give it a description in the snippet file:

<snippet>
    <content><![CDATA[
<script type="text/javascript" src="${1:script.js}">${2}</script>
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>scriptsrc</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html</scope>
    <description>scriptsrc</description>
</snippet>
Sign up to request clarification or add additional context in comments.

6 Comments

Doesn't work. In JavaScript it automatically creates the description from the file name. I don't know why it would be different in HTML.
Added the solution to my post.
BAM! That's it! Now can you explain to me why "source - comment" doesn't apply to HTML?
@mysteryDate, I am not certain, but it seems that the default in ST2 is to only show autocomplete popups when the scope is source.something. Adding that line to your settings file allows popups to appear for text and source scopes.
thnaks @AGS, it was very helpful.
|

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.