Find and replace in project | PyCharm (original) (raw)

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.

Find the search string in a project

  1. Press Ctrl+Shift+F or select from the main menu.
  2. In the search field, type your search string. Alternatively, in the editor, highlight the string you want to find and press Ctrl+Shift+F 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 Alt+Down.
    If you need, specify the additional options.
    Find in Files
    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 Multi-line search icon to enter a new line, and press Ctrl+Alt+Down/Ctrl+Alt+Up to browse through occurrences.
  3. Check the results in the preview area of the dialog where you can replace the search string or select another string, press Ctrl+Shift+F again and start a new search.
  4. 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.

Copy paths or references of the found files

  1. In the list of search results, right-click the result for which you want to copy a path and click Copy/Reference.
  2. 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.

Search in the specific file types

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.

  1. Go to Ctrl+Shift+F.
  2. In the Find in Files dialog, select the File mask checkbox and from the list of file types, select the one you need.
    File mask
    PyCharm limits its search to the specified type.
  3. 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.

Search for usages in a project

You can search for usages of a symbol in your whole project or in a scope that you set.

  1. Go to Ctrl+Shift+F.
  2. Select the symbol for which you want to find usages. Note that you can extend your search to file usages as well.
  3. In the main menu, go to Alt+F7.
  4. Check the results in the Find tool window.
    Find tool window
    You can also pull out the results from the previous Find Usages actions. Go to 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.
    Find tool window preview area
    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 Ctrl+Alt+Shift+F7 to open the Find Usages dialog where you can set a new scope for your search.
    Find usage dialog
    For example, you can set your search scope to production files only or to only open files.
    To set a custom scope, click the ellipsis icon.
  5. 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 Ctrl+Alt+F7. You can use this window for quick navigation.

Find usage dialog

Press the same shortcut again to see the usages in the default scope.

Disable automatic highlighting of usages

When you place the caret at a symbol, the IDE highlights all usages of this symbol in the current file. Use the F3 and Shift+F3 shortcuts to navigate between highlighted symbols.

If necessary, you can disable the automatic highlighting.

When the automatic highlighting is disabled, place the caret at the necessary symbol and press Ctrl+Shift+F7. This will highlight all usages of the symbol in the current file.

Replace the search string in a project

  1. Press Ctrl+Shift+R () to open the Replace in Path dialog.
  2. In the top field, enter your search string. In the bottom field, enter your replacement string.
    Replace in path dialog
    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.
  3. Click one of the available Replace commands.

Last modified: 16 December 2024