Find and replace text in a file
You can quickly find and replace text strings in the current document. Using different options, you can narrow your search process, use regular expressions in your search, and manage your search results.
Open your file in the editor.
Press Ctrl0F or select Edit | Find | Find from the main menu.
note
If you want to extend the search of your target beyond the current file, press CtrlShift0F. For more information, refer to Search for a target within a project.
In the search field that opens, enter your search string. PhpStorm highlights the results of your search in the file. Alternatively, in the editor, highlight the string you want to find and press Ctrl0F. PhpStorm places the highlighted string into the search field.
note
Place the caret at any string in your file and press Ctrl0F to find its occurrences or go to Edit | Find | Next Occurrence of the Word at Caret in the main menu.
You can search for a text string inside a multi-line selection.
note
PhpStorm handles replacing in multi-line selections the same way.
Select a multi-line fragment and press Ctrl0F.
Click , set a tick next to Search In Selection and type your search string. PhpStorm will search for the target inside the selected fragment first.
If you remove the tick next to Search In Selection, PhpStorm will switch the search process back to the whole file.
If you want to search for the multi-line fragment itself, select it and press Ctrl0F.
PhpStorm lets you adjust your search process and perform various actions with the displayed search results.
If you want to see the list of previous searches, press ⌥↓ in the search field.
If you want to enter a multi-line string, click the icon in the search field for a new line.
With selected, PhpStorm automatically escapes special regex symbols with backslash
\
when you search for a text string that contains them.note
Keep in mind that if you copy (Ctrl0C) the string first and then paste (Ctrl0V) it in the search field, the regex symbols will not be taken into account.
For more information about regex, refer to the search with regex documentation.
Use the and arrows to navigate to the previous or the next occurrence.
Work with the list of occurrences AltF7 in the Find tool window, where you have other options, for example, to group your results or to open them in a separate window.
Click for Multiple Cursors selection options: to add a selection of the next occurrence (Alt0J) or to deselect the previous occurrence (AltShift0J).
If you want to quickly replace the target of your search in the whole file, press CtrlAltShift0J and type a new string.
You can narrow your search when you click , in the search field, or click to select a scope for your search.
You can press ^⌥X (previously known as ⌥G) to quickly toggle the Regex option. You can use regular expressions to opt for more challenging searches.
Press Ctrl0R or select Edit | Find | Replace from the main menu to open the Replace in File window.
In the top field, enter your search string. In the bottom field, enter your replacement string. If you need to preserve the case, click located in the replace field.
Click for a multi-line replace. For example, if you want to replace a comma with a comma and a new line, enter a comma in the search field and a comma and the new line in the replace field.
Click Replace to replace items one by one, Replace all to replace all items in your file, and Exclude to omit some items from replacing.
The options that appear in the Replace window, are similar to the Find window and you can refer to the manage the search results section.
Thanks for your feedback!