Sublime Forum

Customizing Sublime Snippet

#1

I love creating id in lower case but the id comment to be uppercase. How can I write lowercase and transform that automatic to uppercase?

For example, my desired result is:

I dont want to write header twice. I want to write it only once and in lowercase but want it to be uppercase in html comment and lowercase as I type in html id. Is it possible?

0 Likes

#2

It’s unclear exactly how you want your snippet to look because you didn’t properly quote the XML of your example snippet, so here’s an example that does what you’re asking, which you can modify as you need:

<snippet>
    <content><![CDATA[
<!-- id is ${1/./\u$0/g} -->
<div id="$1">$0</div>
]]></content>
    <tabTrigger>test</tabTrigger>
    <scope>text.html</scope>
</snippet>

The ${1/./\u$0/g} in the HTML comment means:

This is a mirrored copy of the $1 that the user will enter in the div id field; in this mirror copy match the regular expression . (any character) and replace it with \u$0 (an upper-case version of the match), and do this for every possible regular expression match (g).

More information on how this works is available in the page on snippets in the unofficial documentation.

2 Likes

#3

Perfect Odat; it solved my problem.
I am using this solution: http://prntscr.com/jf8k25

0 Likes

#4

I know how to change text to uppercase in another place using this code:
${1/./\u$0/g}

But if I want to type type any case and want to change that to uppercase in the typing place (not another place); what will be the code?
Such as,
${1:header} allows me to just type but dont change text case. I want to type and change text case in the place I am typing;

0 Likes

#5

As far as I’m aware the only thing that directly controls the text at the point where you’re typing it is you; i.e. you need to use Shift or CapsLock as appropriate.

1 Like

Snippet Text Transform