Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 code snippet not working in proper scope

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?

like image 617
Aaron Krajeski Avatar asked Dec 02 '22 18:12

Aaron Krajeski


1 Answers

"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>
like image 119
AGS Avatar answered Dec 30 '22 12:12

AGS