9

How I can search within a specific block of code or selection in IntelliJ IDEA?

I got used to using this feature in Eclipse. In Eclipse you can just double click on the beginning of a curly bracket, and it'll highlight the entire block of code. After which you could do Command+f
(Ctrl+f on Windows) to search ONLY in the highlighted block, or you could just highlight whatever you need and search just that block of code.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Khon Lieu
  • 4,295
  • 7
  • 37
  • 39

5 Answers5

5

Go to Settings | Keymap, search for the Find... action in the Other group. This action should have the following description:

Find a string in active editor, shows modal dialog

Assign a keyboard shortcut to this action (you need to make a copy of default keymap to modify it), for example Ctrl+Alt+Shift+F.

When in editor, select any block of text, then press this shortcut, a dialog will open with the Scope automatically set to Selected text:

Find Text

To quickly select the method body while standing on the opening curly brace use Ctrl+W.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • I have the latest IntelliJ IDEA Ultimate on Mac OS, I cannot find this functionality there... i.e. there is no "Find a string in ... " I did a search in keymaps and actions using "cmd + A" – tsar2512 May 31 '18 at 15:17
  • @tsar2512 the dialog was replaced with a ribbon at the top of the editor, it can be invoked using [the same shortcut](https://i.imgur.com/EjQPcYw.png). – CrazyCoder May 31 '18 at 19:18
  • couldn't find feature like that in Idea 2018.2 – Davoud Nov 20 '18 at 13:24
  • @BadamchiDavoud please follow https://youtrack.jetbrains.com/issue/IDEA-146832 for updates. – CrazyCoder Nov 20 '18 at 22:36
4

As of 2020, I'm able to perform find in selection on PhpStorm

  • Select the block of text and hit Cmd + F on MacOS / Ctrl + F on other platforms
  • On the find toolbar (that appears on top) there's an In Selection button; use that to limit search scope to the selected text only

enter image description here

Here's the link to my original answer on JetBrains support forums


I'm using

PhpStorm 2020.1.2
Build #PS-201.7846.90, built on June 3, 2020
y2k-shubham
  • 10,183
  • 11
  • 55
  • 131
  • Unlike regular search, search in selection currently doesn't unfold the collapsed pieces of text to show matching text; rather it just should a line indicator before the collapsed piece indicating that a match was found inside it. Hopefully `JetBrains` will fix it overtime – y2k-shubham Jul 09 '20 at 22:41
  • With the new, simplified interface (2023), IntelliJ seems to have taken the wrong cues from the competition: they removed the "In Selection" icon. – John Perry May 04 '23 at 14:52
2

First select some text and press ctrl+R to open the dialog, then check the "in selection" option :

enter image description here

mike
  • 111
  • 1
  • 3
1

In current version, 2020.2, default for Find In Selection is Ctrl+Alt+E.

Screenshot of Find shortcuts

Roger Dahl
  • 15,132
  • 8
  • 62
  • 82
0

On IntelliJ in Mac:

  1. In a file select the specific block in which we want to find something
  2. Press CMD + F
  3. Press CTRL + OPTION + G
  4. Notice that the cursor has automatically landed in the find toolbar's text field
  5. Type in what is intended to be found
  6. Press enter to move the cursor to the first occurrence.
NSaran
  • 561
  • 3
  • 19