Search code examples
phpstormkeyboard-shortcuts

Can I wrap a text selection in a tag in phpstorm?


Suppose I have a text:

This is my text!

How beautiful it is!

And I want to wrap each line within a p-tag, is there an easier way than to navigate to each line and add them manually and have them close semi-automatically?

I want them to look like this:

<p>This is my text!</p>

<p>How beautiful it is!</p>

while having to do as less as possible.


Solution

    1. Select your lines
    2. Code | Surround With...
      For Windows/Linux: Ctrl + Alt + T
      For MacOS: Cmd + Alt + T
    3. Choose "Emmet"
    4. Type p* -- this will surround each line with <p> tag

    Screenshot of PhpStorm Emmet functionality

    NOTE: Empty lines will be wrapped as well so it is better remove them in advance.

    Similar/related case.


    P.S.

    In current versions of IDE the dedicated "Surround with Emmet" action is available which allows you to bring that popup window in one key stroke instead of having going trough via intermediate Surround with... popup menu first.

    That action has no shortcut defined by default, but you can easily change that and assign any desired shortcut in Settings/Preferences | Keymap -- just look for Other | Surround with Emmet action (hint: use search box to speed up your search).