简体   繁体   English

崇高的文字3摘要变量(来自先前的分配)

[英]Sublime text 3 snippet variable from previous assignment

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. 我最近尝试调整为升华文本3而不是我过去几年用于网络开发的netbeans,我真的很喜欢netbeans IDE的功能,尤其是相当于升华代码片段的代码模板,不幸的是我无法从最后一次分配中查找变量,例如在netbeans代码模板中。

this is code template I am using in netbeans 这是我在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 这是我在崇高文字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 简而言之,我要寻找的是netbeans中等同于此的等价物

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

I changed your snippet to the text you had in the Netbeans shortcut: 我将您的代码段更改为您在Netbeans快捷方式中输入的文本:

<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: 在Sublime中的PHP文档中,键入dbg并点击Tab ,将出现以下内容:

PHP调试代码段

syntax highlighting is Neon 语法高亮是霓虹灯

$variable is highlighted, allowing you to replace it with something of your own choosing. $variable突出显示,使您可以用自己选择的内容替换它。

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. 不幸的是,Sublime中没有办法仅使用一个片段来保存上一次分配的值-您将需要一个插件。 Let me know if that's a feature you really need, and I'll see if I can put something together. 让我知道这是否是您真正需要的功能,我将看看是否可以组合在一起。

Forget about ugly print_r code, use dBug library. 忘记丑陋的print_r代码,请使用dBug库。

  1. Download http://dbug.ospinto.com/ and include in your project 下载http://dbug.ospinto.com/并包含在您的项目中
  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 ;-) 请享用 ;-)

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. ctrl + shift + c快捷键用作PHP的漂亮打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM