Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 873
k0pernikus Avatar asked Jun 19 '14 10:06

k0pernikus


People also ask

How do I wrap a selection with an HTML tag in Visual Studio?

Visual Studio 2015 comes with a new shortcut, Shift+Alt+W, that wraps the current selection with a div. This shortcut leaves the text "div" selected, making it seamlessly changeable to any desired tag. This coupled with the automatic end tag replacement makes for a quick solution.


1 Answers

  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).

like image 185
LazyOne Avatar answered Sep 20 '22 04:09

LazyOne