PhpStorm new line in HTML replace

2019-06-10 04:42发布

问题:

For over a year I have been trying to do the simplest thing - do an HTLM/PHP search and replace in several files.

For exapmle if I want to replace

<!DOCTYPE html>

with

<!DOCTYPE html>
<!--
TODO UNIVERSAL
Favicon
Page title
Active page
-->

I get

<!DOCTYPE html> <!--     TODO UNIVERSAL     Favicon     Page title     Active page   -->

I realize search and replace is probably considered old fashioned but I have found it an incredibly useful tool for 30 years.

I have scoured JetBrains web site with no avail and searched here and elsewhere.

I have tried /n, \n, \\n, \\n\\r etc etc and nothing seems to work.

I am sure I am being a dunce but could some other PhpStorm user please enlighten me.

回答1:

Search for:

\<\!DOCTYPE HTML\>

Replace with:

\<\!DOCTYPE html\>\n\<\!\-\-\nTODO UNIVERSAL\nFavicon\nPage title\nActive page\n\-\-\>

Make sure that Regex option is checked

(here on screenshot you see the result of such replacement)


P.S. PhpStorm (and other IDEA-based IDEs) uses \n internally (while editing) for all line endings. And then, when saving, it uses detected/proper line ending.



回答2:

This can be achieved with simple and tiny application geany.

I don't know on which platform you are, but it's available on Ubuntu and Windows both.

  1. You can open all files in whclich you want to search and replace.
  2. Open replace dialog
  3. Enter text in find and replace text box.
  4. Here make sure one thing that you copy and paste "replace" text with new line character from a file opened in geany. New line character will be converted to some non readable character, but don't worry just replace it will be as new line after replace.