2

In PHPStorm, when creating a snippet, you can do something like this:

<!-- $VALUE$ Form Input -->
<div class="form-group">
    <input type="text" name="$NAME$" class="form-control">
</div>

With variables and such, so you can easily write a value. I'm wondering how to do the same thing with Sublime Text 3. This is what I have in my CDATA tag:

<!-- $VALUE Form Input -->
<div class="form-group">
    <input type="text" name="$NAME" class="form-control">
</div>

However, it's not working.

2
  • Not sure, but maybe you want this ${1:defaultVar1} ${2:defaultVar2} . After inserting the snippet you can use tab to move and edit the next field (variable). Commented Jan 18, 2015 at 17:13
  • Note: (added 2023-02-17) Some content in this thread may reference stale links to the SublimeText docs. Readers may experience better results by replacing BEFORE http://docs.sublimetext.info/en/latest with AFTER https://docs.sublimetext.io/guide. Also known as: "Sublime Text Community Documentation" Commented Feb 17, 2023 at 17:13

1 Answer 1

3

Unfortunately, the only variables that are available in snippets are specified in the docs under snippets environment-variables, as well as any you declare in a .tmPreferences metadata file, or in a .sublime-options file. However, you can have predefined values in snippets. For example, this snippet:

<snippet>
    <content><![CDATA[<!-- ${1:VALUE} Form Input -->
<div class="form-group">
    <input type="text" name="${2:NAME}" class="form-control">
</div>$0]]></content>
    <tabTrigger>form_group</tabTrigger>
    <scope>text.html</scope>
</snippet>

gives this result when triggered:

You can then hit Tab and the focus will move from field 1 to field 2:

and again to move to the exit point $0:

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

1 Comment

I think thtat's what the OP needs + 1.

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.