问题
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?
回答1:
"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>
来源:https://stackoverflow.com/questions/19495269/sublime-text-2-code-snippet-not-working-in-proper-scope