PhpStorm 2016.2 find and replace multiline text

You can do multiline Find&Replace with Regex option turned on

Find:

<\?\ninclude \("/inc/db\.php"\);

Replace:

<?php\ninclude "siteheader.php"; \nrequire "class.myclass.inc.php"; \n\$dataBase = new DbObj();

As you can see you need to do some additional work to escape some special characters and put \n instead of new lines, but it works. I've just checked.

P.S. Indeed, it was possible to simply paste multiline text in previous versions, but it's not possible anymore. ;-(


There is no easy to use multi-line search or replace across multiple files (Find/Replace in Path functionality) unfortunately.

Right now you have to use Regex option for that -- that's the only option that works.

Watch these tickets (star/vote/comment) to get notified on any progress in this regard.

  • https://youtrack.jetbrains.com/issue/IDEA-69435
  • https://youtrack.jetbrains.com/issue/IDEA-61925
  • https://youtrack.jetbrains.com/issue/IDEA-145720

Manually making regex-compatible text can be quite problematic .. therefore you might use this few-steps trick:

  1. Type your new text in one file to start with
  2. Select such text and invoke Replace in Path... dialog -- with Regex option pre-selected it should automatically escape your selection to be regex-compatible
  3. Copy that already-escaped text somewhere (just Clipboard should be enough)
  4. Close dialog and go back to original file
  5. Select text you want to replace and invoke Replace in Path... dialog -- it will have your initial text already filled in and regex compatible
  6. Paste previously copied escaped text into Replace field
  7. Execute find/replacement

On related note: https://stackoverflow.com/a/38672886/783119


Type Alt+Enter to add a new line in either the "search" or the "replace" field.

search multiline in PhpStorm

Tags:

Php

Phpstorm