0

I am new to Sublime Text 2, and I am trying to create my own snippet. It is going to be a click function, because I use these quite often. From what I understand at this article, I can use ${1:text} to have that text selected first when I open the function. I am trying to wrap this around the selector. This is my code so far

<snippet>
  <content><![CDATA[

    jQuery("${1:div}").on("click", function () {
      $0
    });

  ]]></content>
  <tabTrigger>clickf</tabTrigger>
</snippet>

I have to use jQuery, because $ breaks the tab selection. So from my understanding, div should be selected. And if there are no indents, it works fine. But I have code that looks like this

<section>
  <div>
    <article>
      clickf --> tab this text
    </article>
  </div>
</section>

The text that is selected is not div anymore. I am unsure of why this behavior is occurring. The number of characters is still the right length, but the text that is selected is now closer to the beginning.

1 Answer 1

3

If you'd rather use $ instead of jQuery you can simply escape it with \. Your snippet works fine for me on two different machines, so maybe you can try escaping the curly braces as well:

<snippet>
    <content><![CDATA[
        \$("${1:div}").on("click", function () \{
              $0
        \});
    ]]></content>
    <tabTrigger>clickf</tabTrigger>
    <description>jQuery Click Event</description>
</snippet>

I would have left this as a comment, but my rep isn't up high enough yet. :)

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

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.