In PhpStorm, if you're editing HTML, you can highlight some code, press Ctrl + Alt + J (default shortcut), and you'll get the option to wrap the highlighted code in an HTML tag of your choice. Useful for quickly wrapping something in a div
, or if you forgot to make a tr
before you made your td
s.
I was wondering if there's an existing similar feature for PHP code?
For instance, if I have a line of code, I want to highlight it, and wrap it in a generic for
-loop.
I was sure I'd seen this before, but it might have been Eclipse or NetBeans.
Create custom Live Template of "surround flavour" (so it can be used with that Code | Surround with Live Template
action that you have mentioned) with desired content.
To have that "surround flavour" (such templates are listed that list) you have to use special $SELECTION$
variable in your template.
Generic stuff for PHP also exist .. but Live Templates are more flexible as you can customize them.
https://www.jetbrains.com/help/phpstorm/surrounding-blocks-of-code-with-language-constructs.html