# Search for a target within a 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](tutorial-finding-and-replacing-text-using-regular-expressions.html) in your search, and manage your search results.

Procedure: Find the search string in a file

1. Open your file in the editor.

2. Press `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS)) or select `Edit | Find | Find`  from the main menu.

> **Note:**
> If you want to extend the search of your target beyond the current file, press `Ctrl+Shift+F` (Windows), `⌘ ⇧ F` (macOS), `⌃ ⇧ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F` (macOS System Shortcuts), `Ctrl+Shift+F` (XWin), `Ctrl+Shift+F` (GNOME), `Ctrl+Shift+F` (KDE), `Ctrl+Shift+F` (Emacs), `Ctrl+Shift+F` (Sublime Text), `⌘ ⇧ F` (Sublime Text (macOS)), `Ctrl+Shift+F` (NetBeans), `Ctrl+Shift+F` (Visual Studio), `⌘ ⇧ F` (Visual Studio (macOS)), `Ctrl+H` (Eclipse), `⌃ H` (Eclipse (macOS)). For more information, refer to [Search and replace a target within a project](finding-and-replacing-text-in-project.html).

3. In the search field that opens, enter your search string. IntelliJ IDEA highlights the results of your search in the file.  Alternatively, in the editor, highlight the string you want to find and press `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS)). IntelliJ IDEA places the highlighted string into the search field.

![Search string](https://resources.jetbrains.com/help/img/idea/2026.2/search_within_a_file.png)

> **Note:**
> Place the caret at any string in your file and press `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS)) to find its occurrencesor go to `Edit | Find | Next Occurrence of the Word at Caret` in the main menu.

Procedure: Find in selection

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

> **Note:**
> IntelliJ IDEA handles replacing in multi-line selections the same way.

1. Select a multi-line fragment and press `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS)).

2. Click ![the Filter Search Results icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.filter.svg), set a tick next to Search In Selection  and type your search string. IntelliJ IDEA will search for the target inside the selected fragment first.

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

![Find in selection](https://resources.jetbrains.com/help/img/idea/2026.2/find_in_selection.animated.gif)

If you want to search for the multi-line fragment itself, select it and press `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS)).

![Multi-line selection search](https://resources.jetbrains.com/help/img/idea/2026.2/multi_line_selection_search.png)

Procedure: Manage your search

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

* The editor automatically scrolls while you type a search query. To disable this behavior, click ![the More button](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.general.moreVertical.svg) and uncheck the Scroll to Results During Typing option.

* If you want to see the list of previous searches, press `⌥↓` in the search field.

![search history](https://resources.jetbrains.com/help/img/idea/2026.2/search_history.png)

* If you want to enter a multi-line string, click the ![Enter a new line](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.searchNewLineHover.svg) icon in the search field for a new line.

* With ![the Regex icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.inline.regex.svg) selected, IntelliJ IDEA 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 (`Ctrl+C` (Windows), `⌘ C` (macOS), `⌘ C` (IntelliJ IDEA Classic (macOS)), `⌘ C` (macOS System Shortcuts), `Ctrl+C` (XWin), `Ctrl+C` (GNOME), `Ctrl+C` (KDE), `Ctrl+Insert` (Emacs), `Ctrl+C` (Sublime Text), `⌘ C` (Sublime Text (macOS)), `Ctrl+C` (NetBeans), `Ctrl+C` (Visual Studio), `⌘ C` (Visual Studio (macOS)), `Ctrl+C` (Eclipse), `⌘ C` (Eclipse (macOS))) the string first and then paste (`Ctrl+V` (Windows), `⌘ V` (macOS), `⌘ V` (IntelliJ IDEA Classic (macOS)), `⌘ V` (macOS System Shortcuts), `Ctrl+V` (XWin), `Ctrl+V` (GNOME), `Ctrl+V` (KDE), `Shift+Insert` (Emacs), `Ctrl+Shift+V` (Sublime Text), `⌘ ⇧ V` (Sublime Text (macOS)), `Ctrl+V` (NetBeans), `Ctrl+V` (Visual Studio), `⌘ V` (Visual Studio (macOS)), `Ctrl+V` (Eclipse), `⌘ V` (Eclipse (macOS))) 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](tutorial-finding-and-replacing-text-using-regular-expressions.html) documentation.

* Use the ![Previous occurrence](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.up.svg) and ![Next occurrence](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.down.svg) arrows to navigate to the previous or the next occurrence.

* Work with the list of occurrences `Alt+F7` (Windows), `⌥ F7` (macOS), `⌥ F7` (IntelliJ IDEA Classic (macOS)), `⌃ U` (macOS System Shortcuts), `Alt+F7` (XWin), `Alt+Shift+7` (GNOME), `Alt+Shift+7` (KDE), `Alt+F7` (Emacs), `Alt+F7` (Sublime Text), `⌥ F7` (Sublime Text (macOS)), `Alt+F7` (NetBeans), `Shift+F12` (Visual Studio), `⇧ F12` (Visual Studio (macOS)), `Ctrl+G` (Eclipse), `⌘ ⇧ G` (Eclipse (macOS)) in the Find tool window, where you have other options, for example, to group your results or to open them in a separate window.

![Found Occurrences in the Find tool window](https://resources.jetbrains.com/help/img/idea/2026.2/find_all_occurrences.png)

* Click ![the More button](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.general.moreVertical.svg) for Multiple Cursors selection options: to add a selection of the next occurrence (`Alt+J` (Windows), `⌃ G` (macOS), `⌃ G` (IntelliJ IDEA Classic (macOS)), `⌃ G` (macOS System Shortcuts), `Alt+J` (XWin), `Alt+J` (GNOME), `Alt+J` (KDE), `Alt+J` (Emacs), `Ctrl+D` (Sublime Text), `⌘ D` (Sublime Text (macOS)), `Alt+J` (NetBeans), `Alt+Shift+.` (Visual Studio), `⌥ ⇧ .` (Visual Studio (macOS)), `Alt+Y` (Eclipse), `⌃ G` (Eclipse (macOS))) or to deselect the previous occurrence (`Alt+Shift+J` (Windows), `⌃ ⇧ G` (macOS), `⌃ ⇧ G` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ G` (macOS System Shortcuts), `Alt+Shift+J` (XWin), `Alt+Shift+J` (GNOME), `Alt+Shift+J` (KDE), `Alt+Shift+J` (Emacs), `Alt+Shift+J` (Sublime Text), `⌃ ⇧ G` (Sublime Text (macOS)), `Alt+Shift+J` (NetBeans), `Alt+Shift+Comma` (Visual Studio), `⌥ ⇧ Comma` (Visual Studio (macOS)), `Alt+Shift+Y` (Eclipse), `⌃ ⇧ G` (Eclipse (macOS))).

* If you want to quickly replace the target of your search in the whole file, press `Ctrl+Alt+Shift+J` (Windows), `⌘ ⌃ G` (macOS), `⌘ ⌃ G` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ G` (macOS System Shortcuts), `Ctrl+Alt+Shift+J` (XWin), `Ctrl+Alt+Shift+J` (GNOME), `Ctrl+Alt+Shift+J` (KDE), `Ctrl+Alt+Shift+J` (Emacs), `Alt+F3` (Sublime Text), `⌘ ⌃ G` (Sublime Text (macOS)), `Ctrl+Alt+Shift+J` (NetBeans), `Alt+Shift+;` (Visual Studio), `⌥ ⇧ ;` (Visual Studio (macOS)), `Ctrl+Alt+Y` (Eclipse), `⌘ ⌃ G` (Eclipse (macOS)) and type a new string.

![Replacing all occurrences](https://resources.jetbrains.com/help/img/idea/2026.2/replace_text_in_file.animated.gif)

* You can narrow your search when you click ![the Words icon](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.inline.exactWords.svg), ![the Match case icon](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.inline.matchCase.svg) in the search field, or click ![the filter icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.filter.svg) to select a scope for your search.

* You can press `^⌥X` (previously known as `⌥G`) to quickly toggle ![the Regex icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.inline.regex.svg) the [Regex](regular-expressions.html) option. You can use [regular expressions](tutorial-finding-and-replacing-text-using-regular-expressions.html) to opt for more challenging searches.

* Press `Ctrl+F7` (Windows), `⌘ F7` (macOS), `⌘ F7` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ U` (macOS System Shortcuts), `Ctrl+F7` (XWin), `Ctrl+F7` (GNOME), `Ctrl+7` (KDE), `Ctrl+F7` (Emacs), `Ctrl+F7` (Sublime Text), `⌘ F7` (Sublime Text (macOS)), `Ctrl+F7` (NetBeans), `Alt+Shift+F11` (Visual Studio), `⌥ ⇧ F11` (Visual Studio (macOS)), `Ctrl+Shift+G` (Eclipse), `⌘ ⇧ U` (Eclipse (macOS)) to see usages of any element in the opened file.

If you don't want IntelliJ IDEA to highlight all found usages in the file, open

the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) 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` (Windows), `⌥ F7` (macOS), `⌥ F7` (IntelliJ IDEA Classic (macOS)), `⌃ U` (macOS System Shortcuts), `Alt+F7` (XWin), `Alt+Shift+7` (GNOME), `Alt+Shift+7` (KDE), `Alt+F7` (Emacs), `Alt+F7` (Sublime Text), `⌥ F7` (Sublime Text (macOS)), `Alt+F7` (NetBeans), `Shift+F12` (Visual Studio), `⇧ F12` (Visual Studio (macOS)), `Ctrl+G` (Eclipse), `⌘ ⇧ G` (Eclipse (macOS)) to [search for usages](find-highlight-usages.html) beyond the current file or `Ctrl+Alt+F7` (Windows), `⌘ ⌥ F7` (macOS), `⌘ ⌥ F7` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ U` (macOS System Shortcuts), `Ctrl+Alt+7` (XWin), `Ctrl+Alt+7` (GNOME), `Ctrl+Alt+7` (KDE), `Ctrl+Alt+F7` (Emacs), `Shift+F12` (Sublime Text), `⇧ F12` (Sublime Text (macOS)), `Ctrl+Alt+F7` (NetBeans), `Alt+Shift+F12` (Visual Studio), `⌥ ⇧ F12` (Visual Studio (macOS)), `Ctrl+Alt+F7` (Eclipse), `⌘ ⌥ F7` (Eclipse (macOS)) to open the search results in a separate popup. If you need to configure some options before the search, press `Ctrl+Alt+Shift+F7` (Windows), `⌘ ⌥ ⇧ F7` (macOS), `⌘ ⌥ ⇧ F7` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ ⇧ U` (macOS System Shortcuts), `Ctrl+Alt+Shift+7` (XWin), `Ctrl+Alt+Shift+7` (GNOME), `Ctrl+Alt+Shift+7` (KDE), `Ctrl+Alt+Shift+F7` (Emacs), `Ctrl+Alt+Shift+F7` (Sublime Text), `⌘ ⌥ ⇧ F7` (Sublime Text (macOS)), `Ctrl+Alt+Shift+F7` (NetBeans), `Ctrl+Alt+Shift+F12` (Visual Studio), `⌘ ⌥ ⇧ F12` (Visual Studio (macOS)), `Ctrl+Alt+Shift+F7` (Eclipse), `⌘ ⌥ ⇧ F7` (Eclipse (macOS)) to open the Find Usages dialog.

Procedure: Replace the search string in a file

1. Press `Ctrl+R` (Windows), `⌘ R` (macOS), `⌘ R` (IntelliJ IDEA Classic (macOS)), `⌘ R` (macOS System Shortcuts), `Ctrl+R` (XWin), `Ctrl+R` (GNOME), `Ctrl+R` (KDE), `Alt+Shift+5` (Emacs), `Ctrl+H` (Sublime Text), `⌘ ⌥ F` (Sublime Text (macOS)), `Ctrl+H` (NetBeans), `Ctrl+H` (Visual Studio), `⌃ H` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+R` (Eclipse (macOS)) 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](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.inline.preserveCase.svg) located in the replace field.

![Replace in file pane](https://resources.jetbrains.com/help/img/idea/2026.2/replace_in_file.png)

Click ![Multi-line](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.searchNewLineHover.svg) 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](#work_with_search_results) section.

