IntelliJ IDEA 2022.1 Help

Search for usages

When you write or edit code, you might come across a code element that you want to change or delete. Before you make the changes, it is a good practice to see where the code element is used and how it affects the application. With the Find Usages actions you can search for the references of your code element throughout the whole codebase.

You can manage the search process, and search only in a single file, extend your search to the whole project, or create a certain search scope. Moreover, you can configure the color of the usages highlighting or disable the automatic highlighting of usages altogether.

Search for usages in a file

  • In the editor, select a symbol you want to find, IntelliJ IDEA automatically highlights all found usages in the file. If the highlighting of usages is disabled, press Ctrl+Shift+F7 to highlight all usages in the file.

    Find usages in file result
  • From the main menu, select Edit | Find Usages | Find Usages in File Ctrl+F7. IntelliJ IDEA selects the first usage occurrence in the file.

    Find usages result

    With the Ctrl+F7 you can also highlight the exception name and places where the exception is thrown.

    Higlight exceptions

Use the F3 and Shift+F3 shortcuts to navigate between highlighted symbols.

Search for usages in a project

  1. Select a symbol for which you want to find usages, right-click the symbol, and select Find Usages from its context menu or press Alt+F7.

  2. Check the results in the Find tool window.

    If you need, you can group (the Group By icon) the results by files, packages, directories, and so on.

    Find tool window

    To open the Find Usages dialog, click Settings icon on the toolbar in the Find tool window or press Ctrl+Alt+Shift+F7.

    While in the Find tool window, you can also 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

    You can use the Find Usages action as an alternative to the Call Hierarchy actions.

    Call hierarchy window

Preview source code for found usages

  1. Select a symbol for which you want to find usages, right-click the symbol, and select Find Usages from its context menu or press Alt+F7.

  2. In the Find tool window, click the Preview Source icon.

Show usages in a separate window

You can view usages of the selected symbol in a separate window that you can move to different parts of your screen and use for quick navigation.

  1. In the editor, select a symbol for which you want to see the usages.

  2. From the main menu, select Edit | Find Usages | Show Usages In Code Ctrl+Alt+F7.

    Show Usages results window

    The usages window shows the current scope and total count of usages. If you want to quickly switch to the default scope, press Ctrl+Alt+F7.

    If the search results have too many entries, then IntelliJ IDEA shows the first hundred usages found and the more usages option on the bottom of the window which you can click to display another hundred usages, and so on until the search is finished.

    more usages

    Use filters on the top of the window to show or hide the certain search entries.

    Show usages: filters

You can configure IntelliJ IDEA to show you usages of Java code symbols in the editor. The Code vision lets you focus on your code, enriched with contextual information and navigation.

Show inlay hints for usages

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Inlay Hints | Java.

  2. From the available options, select Code Vision and enable the Show hints for: and the Usages checkboxes.

  3. Click OK to save the changes.

    When you return to your code in the editor, IntelliJ IDEA will show you the usages of Java symbols. You can click the displayed hint to see and navigate to the needed usage in a separate window.

    Inlay hint: Usages
    Alternatively, you can click the Settings hint to access the related settings.

    If you select the Related problems option in the related settings, IntelliJ IDEA will warn you with an inlay hint about problems in your code that are related to the signature change of a class or a method that has external usages. This feature works for fields as well.

    Inlay hints

    You can click the related problems inlay hint, and check the description of the found problems the Find tool window.

    Find tool window

View recent usages search results

IntelliJ IDEA remembers your Find Usages results, so you don't need to run the action again.

  • From the main menu, select Edit | Find | Recent Find Usages and then select the usage query.

Manage the Find Usages scope

Sometimes, you might want to find usages only in certain files or libraries of your project.

  1. Press Ctrl+Alt+Shift+F7 to open the Find Usages dialog.

  2. In the Find Usages dialog, in the Scope field, select a scope for your search. For example, you can search for usages only in Open Files or only Project Test Files.

    Find Usages dialog (Change Scope)

    You can also set a custom scope by clicking the ellipsis icon. For example, you can create a custom scope to exclude certain files from the search for usages, such as test files. When you are done setting a new scope, click Find.

  3. If IntelliJ IDEA doesn't return any results, it will display a message suggesting that you opt for more options.

    No usages found popup

    You can follow the link or press Ctrl+Alt+Shift+F7 to open the Find Usages dialog again and set a new scope for your search.

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.

If necessary, you can disable the automatic highlighting.

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Editing.

  2. Clear the Usages of element at caret checkbox in the Highlight on Caret Movement section.

When automatic highlighting is disabled, and you want to highlight usages of a symbol in the current file, select this symbol and press Ctrl+Shift+F7. This will highlight all usages of the symbol in the current file.

Change the background color of the highlighted usages

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Color Scheme | General.

  2. From the options on the right, open the Code node and select Identifier under caret.

  3. In the Background field, specify the color you need and save the changes.

Last modified: 10 August 2022