CLion 2024.3 Help

Search for usages

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

  • Place the caret at a symbol and press Ctrl+F7. CLion displays all the usages of the symbol in the file.

    find usages in a file
  • Go to Edit | Find Usages | Find Usages in File Ctrl+F7. CLion selects the first usage occurrence in the file.

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

Search for usages in a project

  • 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.

    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.

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

    CLion analyzes search results, detects the most common usage patterns, and categorizes all found usages into groups based on their structural similarity. These usage clusters appear in the Preview tab.

    You can select any group node from the list and click Show similar usages to look through the results.

    To disable this functionality, unselect the Enable similar usages clustering in Find Usages view in the advanced settings.

    While in the Find tool window, you can use the Preview the Preview Usages button area to check the places where the usages were found, and the Call Hierarchy.

    Find tool window preview area

Preview source code for found usages

You have several options to see the code source for the usages found.

  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 SourcePreview Source icon.

    As an alternative, you can select Jump to Source if you invoke the context menu on a usage found or Show in Split. In this case, the file with the result usage is opened in the editor.

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. Go to Edit | Find Usages | Show Usages In Code Ctrl+Alt+F7.

    Show Usages results window

    If the search results have too many entries, then CLion 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.

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

The usages window shows the results found in the current scope. To quickly switch to the default scope, press the same shortcut Ctrl+Alt+F7 again.

View recent usages search results

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

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

Manage the scope of Find Usages

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 usage dialog

    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.

    If CLion 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.

Change the background color of the highlighted usages

  1. In the Settings 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.

Improve Find Usages with Clangd indexer

CLion incorporates two language engines for C++ code, the built-in engine and the Clangd-based engine. By default, Find Usages are powered by the built-in engine, however, it brings the following downsides:

  • Find Usages is not accurate when looking for constructors which can be used for implicit conversion and for implicit conversion operators.

  • The performance of Find Usages might not be satisfactory in some cases.

Both of these issues can be solved by turning on the Clangd-based indexer.

Enable Clangd indexer

  1. In the main menu, go to Settings | Advanced Settings.

  2. Navigate to the Clangd section and set the Use Clangd-based indexer checkbox:

    Enabling Clangd indexer
  3. Restart CLion.

Check indexer status and memory consumption

After turning on the indexer, you will see a round-ball indicator in the status bar.

  • Green color means the indexer is ready. At this state, the searches are performed instantly, no matter how many usages of a symbol there are in the project. This is especially noticeable with symbols that are used across the whole project or with operators like =, +, -, *.

  • Yellow means that there is an indexer update in progress.

  • Grey means the indexer is paused.

  • You can hover over the indicator to view memory consumption:

    Clangd indexer status

Rebuild or pause the indexer

  • In case the indexer seems broken, click the indicator and select Restart:

    Clangd indexer actions
  • To pause the indexer in order to free the CPU and memory it is using, click the indicator and select Pause.

Adjust the indexer settings

  1. Click the indexer indicator and select Settings:

    Clangd indexer indicator menu - settings
  2. Clangd indexer settings
    • Enable modules - turn off to avoid potential crashes (may cause a slow-down).

    • Enable dynamic index - turn on to improve search speed in the recently opened files.

    • Show progress in the toolbar - enable indexer's progress bar.

  3. Click Apply.

Last modified: 14 October 2024