CLion 2024.1 Help

Find and replace in file

You can quickly find and replace text strings in the current document. Using different options, you can narrow your search process, use regular expressions in your search, and manage your search results.

Find the search string in a file

  1. Open your file in the editor.

  2. Press Ctrl+F or select Edit | Find | Find from the main menu.

  3. In the search field that opens, enter your search string. CLion highlights the results of your search in the file. Alternatively, in the editor, highlight the string you want to find and press Ctrl+F. CLion places the highlighted string into the search field.

    search string

Find in selection

You can search for a text string inside a multi-line selection.

  1. Select a multi-line fragment and press Ctrl+F.

  2. Click the Filter Search Results icon, set a tick next to Search In Selection and type your search string. CLion will search for the target inside the selected fragment first.

    Find in selection

    If you release remove the tick next to Search In Selection, CLion will switch the search process back to the whole file.

    If you want to search for the multi-line fragment itself, select it and press Ctrl+F.

    Search for a multi-line selection

Manage your search

CLion lets you adjust your search process and perform various actions with the displayed search results.

  • To see the list of previous searches, click the magnifier glass icon or press ⌥↓ in the search field.

    search history
  • If you want to enter a multi-line string, click the Enter a new line icon in the search field for a new line.

  • With the Regex icon selected, CLion automatically escapes special regex symbols with backslash \ when you search for a text string that contains them.

    For more information about regex, refer to the search with regex documentation.

  • Use the Previous occurrence and Next occurrence arrows to navigate to the previous or the next occurrence.

  • Click the Add selection for the next occurrence or unselect the previous occurrence icon to add a selection of the next occurrence or deselect the previous occurrence Alt+J or Alt+Shift+J.

  • If you want to quickly replace the target of your search in the whole file, press Ctrl+Alt+Shift+J and type a new string.

    Replacing all occurrences
  • You can narrow your search when you click the Words icon, the Match case icon in the search field, or click the filter icon to select a scope for your search.

  • You can press ^⌥X (previously known as ⌥G) to quickly toggle the Regex icon the Regex option. You can use regular expressions to opt for more challenging searches.

  • Press Ctrl+F7 to see usages of any element in the opened file.

    If you don't want CLion to highlight all found usages in the file, open the Settings dialog (Ctrl+Alt+S) and on the Editor | Code Editing page, under the Highlight on Caret Movement section, clear the Usages of element at caret option.

    Press Alt+F7 to search for usages beyond the current file or Ctrl+Alt+F7 to open the search results in a separate popup. If you need to configure some options before the search, press Ctrl+Alt+Shift+F7 to open the Find Usages dialog.

Replace the search string in a file

  1. Press Ctrl+R or select Edit | Find | Replace from the main menu to open the Replace in File window.

  2. In the top field, enter your search string. In the bottom field, enter your replacement string. If you need to preserve the case, click the Preserve Case icon located in the replace field.

    Replace search string in file

    Click Multi-line for a multi-line replace. For example, if you want to replace a comma with a comma and a new line, enter a comma in the search field and a comma and the new line in the replace field.

  3. Click Replace to replace items one by one, Replace all to replace all items in your file, and Exclude to omit some items from replacing.

The options that appear in the Replace window, are similar to the Find window and you can refer to the manage the search results section.

Last modified: 30 May 2024