intelliJ -> is there any way to scope your search to be within a function

There is a way to search inside a method, however, it doesn't seem to work for other scopes.

When searching in file as usual, click "Find all" find all button in search toolbar

You'll get a list of results in the bottom panel. If you enable "Group by file structure" (I had it disabled by default), you can get a list of matches for a particular method. group by file structure button in search results panel


Looks like we're finally getting this feature in IDEA 2019.3:

https://blog.jetbrains.com/idea/2019/09/whats-new-in-intellij-idea-2019-3-eap-2/ (Ctrl-F for subtitle "Ability to search in a selected area when using the Find action")

It’s now possible to search only in a selected area using the Find action (cmd+F / Ctrl +F). Simply select the code piece you need in the editor and invoke the Find action and the IDE will perform the search only in the selected area.

Screenshot from the article (was a GIF originally)

enter image description here


Using IntelliJ IDEA 2018.1.4 (Ultimate Edition), Build #IU-181.5087.20 on Ubuntu 18.04, you can do it like this (mentioned key maps are for Linux):

Let's take as example the following code, where we will be searching for the word "key" inside the method "clear". As you can see there are many occurrences of that word (in red, highlighted the ones we want in our results, and in blue other occurrences, which we do not want to appear in our search results)

Image of IntelliJ IDEA Editor with the searched word

1- Select the area you want to limit the search scope to.

Image of IntelliJ IDEA Editor with the searched word scoped inside some area

2- Press Ctrl+Shift+F. It will pop up a search window with the selected text pre-filled in the search box.

3- Select the options "Scope" and, in the combo next to it, "Selection" (if they are not selected by default)

Image of the pop up shown by IntelliJ IDEA for searching the word in the selected scope inside the current editor

4- Type the word(s) you want to search (in this example, the key word).

enter image description here

5- The results shown will be limited to the selected area. Notice how there are only 9 matches in the upper right corner ("Match case" option is checked), despite in the same file there are many other ocurrences of the same word.


However I was neither able to find a key combination in order to do this as a single action nor assign a new one. Also, notice how the search includes the text in the method documentation.