Replace text
Replace text in the current file
To replace text in a file that's currently opened in the editor:
- Press
Ctrl+R
.
Or:
- Select Edit > Find > Replace on the main menu.
A toolbar appears at the top of the window. Use the upper part to specify what you want to replace—the search—and the lower part to specify the replacement.
Search options
- To perform case sensitive searches select Match Case .
- To match whole words only select Words .
- To interpret search criteria as a regular expression select Regex .
- To limit the search to a part of the code, for example comments, select Show Filter Popup and choose from the list.
- To toggle the use of selected text as the scope of the search select In Selection .
Search
To perform a search, enter the search criteria in the search box: all the search criteria occurrences are immediately highlighted in the text.
The number of matches is shown in the right part of the toolbar
- To create multi-line search criteria select New Line or press
Ctrl+Shift+Enter
. - To clear the search criteria select the "X" icon .
- To use previous search criteria select Search History and choose from the list.
To use existing text as the search criteria:
- Select the text to use as search criteria.
-
Press
Ctrl+R
.Or:
Select Edit > Find > Replace on the main menu.
Use the results
- To move to the previous match select Previous Occurrence .
- To move to the next match select Next Occurrence .
- To select all the matches select Select All Occurrences .
- To view all the occurrences of the text to replace in the IntelliJ IDEA Find tool window, select Open in Find Tool Window .
Replace
Enter the replacement text in the second box from above—the replacement box.
- To create multi-line replacement text select New Line or press
Ctrl+Shift+Enter
. -
To make the replacement text inherit the case of the replaced text, select Preserve case or press
Alt+E
.Example
With Preserve case on, if you make a case insensitive search for legend and your replacement text is history, Legend will be found and it will become History because it will inherit the case of Legend.
-
To clear the replacement text select the "X" icon .
- To re-use replacement text select Replace History .
- To replace matches one by one select Replace.
- To replace all matches at once select Replace All.
- To exclude a match from replacement, select Exclude; select Include to re-include it.
Info
To replace all or some occurrences of a simple string (not a regular expression) in the file you can also use the find function with the selection of the matches. After you have selected the matches, you just have to type the replacement text once and all the occurrences will be changed simultaneously. Similarly, you can use use multiple string selection and then enter the new text.
For more information about searching and replacing in a file see the IntelliJ IDEA documentation.
Replace text in the project, in a module, in a directory or in a scope
To replace text in all the files contained in the project, in a project module, in a directory or in a scope, select Edit > Find > Replace in Files on the main menu.
The Replace in Files window appears.
Search options
- To perform case sensitive searches select Match Case .
- To match whole words only select Words .
- To interpret search criteria as a regular expression select Regex .
- To limit the search to files with a given extension, check File mask and choose the extension from the list.
- To limit the search to a part of the code, for example comments, select Show Filter Popup and choose from the list.
-
To set the scope of the search, choose between In Project, Module, Directory and Scope.
-
If you choose Module, select the module from the list.
-
If you choose Directory:
- Enter the directory path
Or:
-
Select the ellipsis button or press
Shift+Enter
to select the directory path. -
To toggle recursive search in sub-directories, select Search recursively in subdirectories .
-
If you choose Scope:
-
Select the scope from the list.
-
To manage scopes select the ellipsis button or press
Shift+Enter
.
More about scopes in the IntelliJ IDEA documentation.
-
-
-
To pin the window select Pin Window .
- To open the results in a new tab, optionally check Open results in new tab.
- To view all the occurrences of the text to replace in the IntelliJ IDEA Find tool window, press
Ctrl+Enter
or select Open in Find Window.
Search
To perform a search:
- Enter the search criteria in the search box: search results appear below.
- To create multi-line search criteria select New Line or press
Ctrl+Shift+Enter
. - To clear the search criteria select the "X" icon .
- To use previous search criteria select Search History and choose from the list.
Use the results
The number of files and the number of matches are displayed above the search box.
Matches are highlighted inside the results.
The name of the file and the line number is shown to the right of each result.
A preview of the result in the context of the file is displayed below the results.
Hover over the preview area and select Soft-Wrap Preview Editor to activate the soft-wrap.
To jump to the line of code in the editor corresponding to a result, double-click the result.
Replace
Enter the replacement text in the second box from above—the replacement box.
- To create multi-line replacement text select New Line or press
Ctrl+Shift+Enter
. - To make the replacement text inherit the case of the replaced text, select Preserve case or press
Alt+E
. - To clear the replacement text select the "X" icon .
- To re-use replacement text select Replace History .
- To replace matches one by one select Replace.
- To replace all matches at once select Replace All.
Info
For more information about searching and replacing in path see the IntelliJ IDEA documentation.