0

I tried using snippets in Sublime Text - I created a document hello.sublime-snippet in /Users/davidfaux/Library/Application Support/Sublime Text 2/Packages/User:

<snippet>
  <content><![CDATA[
  alert("hello {$1}");
]]></content>
  <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  <!-- <tabTrigger>hello</tabTrigger> -->
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <!-- <scope>source.js</scope> -->
</snippet>

Then, I created a new file called hello.js on my Desktop:

document.onload = function() {
  hello
}

However, when I press tab after hello, nothing happens. Why not? I tried setting "auto_complete_commit_on_tab": true in my User settings, and this attribute seems to be working for autocomplete.

Any advice on directions for debugging appreciated!

3 Answers 3

1

You are using a template to create this snippet. So you need to uncomment the lines that actually define the snippet.

The quick way to do this in ST2 is to select the entire line and press ctrl+shift+/ to remove the comment markings.

The lines you need to uncomment are the <tabTrigger>hello</tabTrigger> line and the <scope>source.js</scope> line. Then this snippet should work fine as long as you are putting it in a .js file.

Also, I prefer using Enter to auto-complete as Tab is also used in ST2 for navigation.

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

Comments

1

As others have mentioned, the parts of the snippet that determine its tab trigger are currently commented. XML comments look like this:

<!-- ...commented content... -->

You've left both the tabTrigger tag line and the scope tag line commented, so hello will not expand to the snippet content—the only way to activate the snippet now is via the Command Palette—nor is the snippet's scope actually restricted to Javascript files. You'll have to remove the commenting from those lines (Ctrl+/ is the default single-line comment toggle on Windows) for them to have any effect, like this:

<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>hello</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>

You can read more about snippets at the Unofficial Docs Snippets page.

Comments

0

Uncomment <tabTrigger> and it will work when you press tab after hello

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.