3

I recently try to adjust to sublime text 3 instead of netbeans which I was using for web development for the last years, I really liked the features in netbeans IDE especially the code templates which is the equivalent to sublime snippets, unfortunately I wasn't able to find the variable from last assignment like in netbeans code templates.

this is code template I am using in netbeans

error_reporting(E_ALL);
ini_set('display_errors', '1');
echo '<pre style="background: black;color: white; font-size:16px; font-wheight:bold; direction:ltr!important;text-align: left;">';
print_r(${VARIABLE variableFromPreviousAssignment default="$variable"});
echo '</pre>';
die();

this is the snippet I am using in sublime text 3

<snippet>
    <content><![CDATA[
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo '<pre>';
echo print_r(${1:*});
echo '</pre>';
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>dbg</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.php</scope>
    <description>dbug snippet</description>
</snippet>

In simple words what I am looking for is the equivelent in sublime to this in netbeans

(${VARIABLE variableFromPreviousAssignment default="$variable"}

4 Answers 4

1

I changed your snippet to the text you had in the Netbeans shortcut:

<snippet>
    <content><![CDATA[
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo '<pre style="background:black; color:white; font-size:16px; font-weight:bold; direction:ltr!important; text-align:left;">';
print_r(${1:\$variable});
echo '</pre>';
die();
]]></content>
    <tabTrigger>dbg</tabTrigger>
    <scope>source.php</scope>
    <description>dbug snippet</description>
</snippet>

In a PHP document in Sublime, type dbg and hit Tab, and the following will appear:

PHP Debug snippet

syntax highlighting is Neon

$variable is highlighted, allowing you to replace it with something of your own choosing.

For more information on snippets, check out the snippet reference.

Unfortunately, there is no way in Sublime to save the value of the last assignment just using a snippet - you'll need a plugin for that. Let me know if that's a feature you really need, and I'll see if I can put something together.

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

1 Comment

Thank you for your answer. So there is no such feature out of the box?The point its realy easy when it automatically puts the last variable in the point you defined. If you can do that please tell me how would it demand plugin development?
0

Forget about ugly print_r code, use dBug library.

  1. Download http://dbug.ospinto.com/ and include in your project
  2. Add the following function in your project:

    /**
     * Returns dBug object [pretty object/array]
     * @param $var
     * @param bool $stop
     */
    function dbug($var,$stop=FALSE) {
        if ( ! class_exists('dbug') ) {
            require '../path_to/dbug.php';
        }
    
        new dBug($var);
        if ( $stop ) die();
    }
    
    1. Enjoy ;-)

1 Comment

I use it in specific cases when I have really large and multy dimentional arrays or huge object this is the second snippet
0

On menu bar open Preferences -> Key Bindings :

Now add below code on right-side of Key Bindings within square bracket []

{ 
    "keys": ["ctrl+shift+c"],
    "command": "insert_snippet",
    "args": { "contents": "echo \"<pre>\";\nprint_r(${0:\\$variable_to_debug});\necho \"</pre>\";\ndie();\n" }
}

Enjoy your ctrl+shift+c shortcut as a Pretty Print of PHP.

Comments

0

<snippet>
    <content><![CDATA[
        error_reporting(E_ALL); 
        ini_set('display_errors', '1'); 
        echo '<pre style="background: black;color: white; font-size:16px; font-weight:bold; direction:ltr!important;text-align: left;">'; 
        print_r(${1:$variable}); 
        echo '</pre>'; 
        die(); 
    ]]></content> 
    <!-- Optional: Set a description --> 
    <description>PHP Debug Preformatted Output</description> 
    <!-- Shortcut Trigger --> 
    <tabTrigger>pre</tabTrigger> 
    <!-- Scope (only in PHP files) --> 
    <scope>source.php</scope> 
</snippet>

Comments

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.