I want to add some custom tags for my development – but I don’t know how to do it.
I have tried snippets but it doesn’t work because my tags have some special symbols. How can I add my tags so that the snippets work?
Eg: when I fill pre in sublime text, it will auto-fill:
echo “<pre>”;
print_r();
echo “</pre>”;
You can use sublime snippets, but you just need to escape the $ sign, as sublime thinks it’s a variable, instead of an actual character you want to print out.
To create a snippet, in the top bar go to Tools > New Snippet.
You save these snippets as presnippet.sublime-snippet in the /packages/user folder (it should save there automatically when you go to save it).
For your first one you can use the following snippet, you have to excape the $ sign by adding \ in front of it:
<snippet>
<content><![CDATA[
echo “<pre>”;
print_r();
echo “</pre>”;
]]></content>
<tabTrigger>pre</tabTrigger>
</snippet>
We can make it better:
<snippet>
<content><![CDATA[
echo “<pre>”;
print_r(${1:\$arr});
echo “</pre>”;
]]></content>
<tabTrigger>pre</tabTrigger>
</snippet>
<!– $1 the cursor will blink here –>
<!– \$arr: \$ convert $ –>
Same method, when I fill arr in sublime text, it will auto-fill:
$arr=[1,3,5,7,9];
and the cursor blinks under this line.
Method: You save the following snippets as arrsnippet.sublime-snippet in the /packages/user folder (it should save there automatically when you go to save it).
<snippet>
<content><![CDATA[
\$arr=[1,3,5,7,9];
$1
]]></content>
<tabTrigger>arr</tabTrigger>
</snippet>
<!– $1 the cursor will blink here –>
<!– \$arr: \$ convert $ –>