Is it possible to define some sort of capitalize()
or toLowerCase()
function when creating Sublime Text 2 Snippets?
For example:
<snippet>
<content><![CDATA[
<?php
class ${1} extends Datamapper
{
var \$has_one = array();
var \$has_many = array();
var \$table = '${1}s';
//constructor and other stuff next...
}
?>
]]></content>
<tabTrigger>dmm</tabTrigger>
</snippet>
This particular snippet helps me create Datamapper ORM models on the fly. When I type dmm
the Snippet is fired and my cursor is placed in two areas at the same time; the class's name & the assignment to $table
. The first cursor requires capitalization whereas the second cursor should not. Can I force the Snippet's case? Something like {1.toLowerCase}
Simple example, but I can think of other times when I could use this.
You can use substitution and the Perl format string syntax
I have tested this code:
<snippet>
<content><![CDATA[
<?php
class ${1} extends Datamapper
{
var \$has_one = array();
var \$has_many = array();
var \$table = '${1/(.+)/\L\1/g}s';
//constructor and other stuff next...
}
?>
]]></content>
<tabTrigger>dmm</tabTrigger>
</snippet>
Regards, Armando
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With