-> shortcut?

I don't do a great deal of PHP, it's mainly something I use on my home projects. One thing that really annoys me is having to type '->' when calling methods on objects. I find I sometimes have to think about the key combination, which can distract from the task at hand. Is there a way to set a shortcut for this, such as typing '..' and having it replaced as '->'? I'd still want to be able to type '...' in comments, though I guess it wouldn't be a major loss if the only solution sacrificed this.

I know it sounds lazy, but that's why I'm in software development - to make repetitive things easy! I'm also using IntelliJ, as opposed to PhpStorm, but I guess that shouldn't make a difference. Any thoughts appreciated.

3 comments
Comment actions Permalink

Hi Aaron,

If I would have to do something like this I would do it via "File | Settings | Live Templates" (but I would prefer to use ,. (coma dot) instead of .. (dot dot) as this combination is unlikely to appear in anyy language construct compared to .. (like ... in comments) where you can press Expand button accidentally).

On that page (Live Templates):
1. Click "Add" button
2. Fill all fileds: Abbreviation: ,.
3. Group: PHP
4. Description: (whatever you like)
5. Template Text: ->
6. Context: PHP
7. Expand With (select the desired key -- you would need to press it in order ,. to become ->)
8. OK -- now test it.

0
Comment actions Permalink

Also you can record a macro (Tools|Start macro recording) and assign a shortcut (Settings|Keymap|Macro) to it.

0
Comment actions Permalink

Thank you, both very helpful answers. Live templates would be even better if there was an option to trigger it without pressing tab, space or enter. With macros, if you assign '->' to a macro triggered by a double key combination (eg '.' followed by '.'), then I find I can no longer type '.' at all. But it would be good to assign a function key to the macro if I did more PHP.

Thanks again!

0

Please sign in to leave a comment.