Search code examples
sublimetext3sublimetextsublimetext-snippet

Sublime Text 3 - How can i add my PHP tags


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 z_z in sublime text, it will auto-fill:

print("<pre>".print_r($files,true)."</pre>");

When I fill z_d, it will auto-fill:

echo "<pre>" . preg_replace("/\]\=\>\n(\s+)/m", "] => ", $dump) . "</pre>";

Solution

  • 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 mysnippet.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 \ infront of it:

    <snippet>
    <content><![CDATA[
    print("<pre>".print_r(\$files,true)."</pre>");
    ]]></content>
        <tabTrigger>z_z</tabTrigger>
    </snippet>
    

    For your second one also use a snippet and escape the $ sign again using a backslash (\) again:

    <snippet>
    <content><![CDATA[
    echo "<pre>" . preg_replace("/\]\=\>\n(\s+)/m", "] => ", \$dump) . "</pre>";
    ]]></content>
        <tabTrigger>z_d</tabTrigger>
    </snippet>