searchintellij-idea

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


Very often while coding, I need to search for keywords which are common and happen throughout a large file, but I am looking for an instance within a function.

The default search functionality often gives me all results starting from the top. Is there any way/workflow to search only within a specific method/function or block of code?


Solution

  • 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

    Another example:

    enter image description here