Find and replace in project
You can search for a text string within a project, use different scopes to narrow your search process, exclude certain items from your search, find usages and occurrences.
Press or select Edit | Find | Find in Files from the main menu.
In the search field, type your search string. Alternatively, in the editor, highlight the string you want to find and press or from the context menu, select Find in Files. PyCharm places the highlighted string into the search field.
To see a list of your previous searches, press .
If you need, specify the additional options.
PyCharm lists the search strings and the files that contain them. If the search string is found several times on the same line of code, PyCharm merges the results in one line.
To do a multi-line search, click the icon to enter a new line, and press / to browse through occurrences.
Check the results in the preview area of the dialog where you can replace the search string or select another string, press again and start a new search.
To see the list of occurrences in a separate tool window, click Open in Find Window. Use this window and its options to group the results, preview them, and work with them further.
If you want to see each new search result in a separate tab in the Find tool window, select the Open Results in New Tab checkbox on the bottom of the Find in Files dialog.
In the list of search results, right-click the result for which you want to copy a path and click Copy/Reference.
In the Copy window, select the path or reference you need.
You can use different options in the Find in Files dialog to adjust your search process.
Select options such as Words () or Match case () to find the exact word in a project or match the letter case.
With selected, PyCharm 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 () the string first and then paste () 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.
Click the icon to filter your search. For example, you can filter the search to omit comments or search only in comments instead.
Select one of the displayed options such as Module or Directory to limit your search.
Moreover, you can select the Scope option that offers you a list of for your search. For example, you can limit your search only to the open files in your project.
If you work without tabs, the scope Recently Viewed Files or Recently Changed Files option might become useful. You can also create your own custom scope, click the Browse icon () to open the Scopes dialog.
Use the File mask option to narrow your search to a specific file type. You can select the existing file type from the list, add a new file type, or add an additional file mask syntax to search for file types with certain patterns.
Go to Edit | Find | Find in Files .
In the Find in Files dialog, select the File mask checkbox and from the list of file types, select the one you need.
PyCharm limits its search to the specified type.
If you don't find the file type you need in the list, enter your file type in the File mask field.
You can manually add a file mask in the search field. If necessary, specify several file types separating them with commas.
You can search for usages of a symbol in your whole project or in a scope that you set.
tip
Click to open the Find Usages dialog.
Go to Edit | Find | Find in Files .
Select the symbol for which you want to find usages. Note that you can extend your search to file usages as well.
In the main menu, go to Edit | Find | Find Usages .
tip
To see usages of the selected symbol within a file, right-click the context menu in your file and select Find Usages .
Check the results in the Find tool window.
tip
Click to open the Find Usages dialog.
You can also pull out the results from the previous Find Usages actions. Go to Edit | Find | Recent Find Usages and the usage query.
While in the Find tool window, you can use the Preview area to check the places where the usages were found, to see a call hierarchy for methods, data flow for fields, and so on.
If PyCharm doesn't return any results, it will display a message suggesting to opt for more options. You can follow the link or press to open the Find Usages dialog where you can set a new scope for your search.
For example, you can set your search scope to production files only or to only open files.
To set a custom scope, click .
When you are done setting a new scope, click Find.
If you want PyCharm to show you usages of the selected symbol in the separate window, press . You can use this window for quick navigation.
Press the same shortcut again to see the usages in the default scope.
tip
To view the results of previous Find Usages actions, go to Edit | Find | Recent Find Usages in the main menu, and then select the usage query.
When you place the caret at a symbol, the IDE highlights all usages of this symbol in the current file. Use the and shortcuts to navigate between highlighted symbols.
note
In the Power Save Mode, highlighting of usages is disabled.
If necessary, you can disable the automatic highlighting.
In the Settings dialog () , go to Editor | General, and clear the Highlight usages of element at caret checkbox.
When the automatic highlighting is disabled, place the caret at the necessary symbol and press . This will highlight all usages of the symbol in the current file.
Press (Edit | Find | Replace in Path) to open the Replace in Path dialog.
In the top field, enter your search string. In the bottom field, enter your replacement string.
For example, if you want to replace a variable name with a new name for a large project, use the Replace in path instead of the Rename refactoring since your variable can appear in the config files as well.
Click one of the available Replace commands.