Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search inside a specific block of code in IntelliJ IDEA?

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.

like image 579
Khon Lieu Avatar asked Jun 01 '11 22:06

Khon Lieu


2 Answers

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.

like image 99
CrazyCoder Avatar answered Oct 26 '22 01:10

CrazyCoder


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
like image 30
y2k-shubham Avatar answered Oct 26 '22 00:10

y2k-shubham