136

I have a few different project with the same core.

All I need is to mark all not current projects as excluded to avoid searching through them (simple search, shift + cmd + n etc.)

In other words I want to have a search results from the core + current project.

Is there are any way do close some projects but have them available in the projects list and open it so easy as it was closed? Or probably you have another experience?

enter image description here

Andrew
  • 18,680
  • 13
  • 103
  • 118
Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55
  • 9
    Exclude from normal text search -- easy -- just define custom scope (Preferences | Scopes) and use it in "Find/Replace in path" and similar dialogs. But this will not work for "Navigate | File/Class/Symbol" as it always works with whole project. Instead of that -- better reorganize your folder structure ("having hide this folder because I do work with another one" is not correct approach). – LazyOne May 15 '13 at 17:20
  • Yeah, I one of the ways to do what I want is to create for each folder separate project and create symlink to the `core` folder. But I am looking for alternative ways. – Vitalii Petrychuk May 15 '13 at 17:34
  • 1
    Not necessary symlink (although I'm using that as well -- work fine for me). You can attach it as Additional Content Root instead (Preferences | Directories). – LazyOne May 15 '13 at 18:50
  • Great! Please post your response as an answer and I will accept it. – Vitalii Petrychuk May 15 '13 at 18:54

4 Answers4

94

To apply custom search use Scopes Settings/Preferences > Appearance & Behavior > Scopes to use it for Find in Path or Replace in Path.
I suggest to reorganize your folders, so that no unnecessary files are left in project directory. Also, you can specify Source Root by going to Settings > Project Settings > Directories and adding additional directories.

SteveExdia
  • 321
  • 1
  • 3
  • 11
Justinas
  • 41,402
  • 5
  • 66
  • 96
90

This is the best way to exclude directories from your search results. I work on large Magento project with many directories I don't want in search results. This solved my problem. If your project contains a /vendor directory, this will help speed up indexing in PHPStorm since it's ignored.

Right click on any folder to bring up the following options.

Exclude from search

TheRealJAG
  • 1,978
  • 20
  • 16
  • Also works for Laravel package development. Recommended way to do this to create packages folder in your project root. Now it will be using same classes as your main project so you end up getting ton of duplicate classes exists errors. Right click and do this and it works like magic. The scope approach didn't work for me! – Juha Vehnia Jun 02 '20 at 23:36
  • tap-and-enjoy solution – CodeToLife Sep 06 '21 at 13:15
41

As of version 2016.3 this is found under Settings > Appearance & Behavior > Scopes.

Or regardless of the version, just go to Settings and type "scopes" into the search box at the top.

Then just click the + symbol to add the scope, choose the folder you want to exclude, and click Exclude Recursively and apply.

Then when you search using CTRL+SHIFT+F, under Options > Scope select Custom and choose the scope you just created (thanks commenters).

Andrew
  • 18,680
  • 13
  • 103
  • 118
  • 4
    Just want to add if you are using FIND like cmd+shift+F then in the options tab you can radio custom and then choose the ellipse and it opens the scope tool and you can selct or create a scope to exclude what you need. – daveferrara1 Jan 14 '17 at 00:17
  • 4
    `This automatically excludes this folder's contents from the searches...` after I have created my custom scope, my search Ctrl+Shift+F was still searching globally until I have explicitly selected "Custom" and picked my scope as @daveferrara1 suggested. – Dimitry K Apr 03 '17 at 11:42
  • 1
    In 2020: After clicking + the `Local` vs `Shared` choice means whether the exclusion goes into VCS or not. Then you have to **Name** it. Then after @DimitryK's step (now called the `Scope` tab) you have to choose that same name in a drop-down menu. (Is Jetbrains UX tinkering turning anyone else into a grumpy old man?) – Bob Stein Jul 21 '20 at 15:11
2

Like @Justinas and commenters said: You could make a custom scope and annoy yourself every time by selecting that custom scope when using Find in Path (and similar) because PhpStorm does not use that custom scope by default ‍♂️

Excluding the node_modules directory breaks autocompletion and other code assistance functionality anyway. You don't want to do that.

However, I found a hack which does not require any directory exclusion of node_modules nor a custom scope:

  1. Close PhpStorm. Ensure it's not running.
  2. Open name_of_your_project.iml in the .idea directory within your project directory with your favourite text editor. As long as it isn't PhpStorm.
  3. Remove the line <content url="file://$MODULE_DIR$/node_modules" />
  4. Save.
  5. Enjoy life again.

I find it amateurish of JetBrains to include dependency storage directories like node_modules of JavaScript/TypeScript and vendor of PHP by default. There is barely any use case to include those directories in find & replace functionality, left alone refactor functionality.

RoestVrijStaal
  • 151
  • 2
  • 7