简体   繁体   English

在Intellij / Phpstorm中自动添加$ this的快捷方式/功能

[英]Shortcut/feature for prepending $this automatically in Intellij/Phpstorm

Is it possible/does such feature exist that when I write an instance variable name (without $this->) it would search for a declared variable? 是否存在/是否存在这样的功能,即当我编写实例变量名称(不带$ this->)时,它会搜索已声明的变量吗? I think it would save a bit of time not writing $this-> anytime I need to access an instance variable. 我认为在我需要访问实例变量时不写$ this->会节省一些时间。

Currently such functionality is not available in PhpStorm. 目前,PhpStorm中不提供此类功能。

https://youtrack.jetbrains.com/issue/WI-19345 -- watch this ticket (star/vote/comment) to get notified on progress. https://youtrack.jetbrains.com/issue/WI-19345-观看这张票(star / vote / comment)以获取进度通知。


Right now I may only suggest to write custom Live Template that would convert t[TAB] (or whatever abbreviation you desire) to $this-> with code completion popup already shown. 现在,我可能只建议编写自定义实时模板 ,该模板会将t[TAB] (或您想要的任何缩写)转换为$this->并且已经显示了代码完成弹出窗口。

Related: https://youtrack.jetbrains.com/issue/WI-551 相关: https : //youtrack.jetbrains.com/issue/WI-551

If all you need is save yourself the trouble of writing $this-> , join the club. 如果您所需$this->就是省去编写$this->的麻烦,请加入该俱乐部。 :) Macros are here for rescue. :)宏在此处用于救援。

I solved this problem by recording a Macro and then binding it with a keyboard shortcut: 我通过录制宏,然后使用键盘快捷键将其绑定来解决此问题:

  1. Go to Edit | 转到编辑| Macros | 宏| Start Macro Recording 开始宏录制
  2. Type '$this->' 输入'$ this->'
  3. Stop Macro Recording using the button in the lower right corner, then name it whatever you want. 使用右下角的按钮停止宏录制,然后将其命名为任意名称。
  4. Assign Shortcut to it: 为其分配快捷方式:
    • Go to File | 转到文件| Settings | 设置| Keymap | 按键图| Macros 巨集
    • Right click and choose 'Add Keyboard Shortcut' 右键单击并选择“添加键盘快捷键”

I chose Ctrl+. 我选择了Ctrl+. as the shortcut and now I am more than happy. 作为捷径,现在我很高兴。 :) :)

I have answered a similar question here 在这里回答了类似的问题

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

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