Ignore a folder in search results - intellij-idea
I'm searching for a string and getting matches in a source folder, and a build folder (file in source gets copied to build during build).
I do not need the build folder result.
Vim has wildignore which helps filter out results.
Is there something similar in intelij?
Mark your build folder as excluded:
File > Project Structure > Modules > Sources > Mark as Excluded (red icon)
You can also just right click on your folder and select Mark Directory As > Excluded.
Excluded folders (shown as rootExcluded) are ones that IntelliJ IDEA "partially ignores". Very limited coding assistance is provided for files in excluded folders. Classes contained in excluded folders don't appear in code completion suggestion lists, references to such classes are shown in the editor as unresolved. When searching, IntelliJ IDEA doesn't look in excluded folders, etc.
Source
Note: See the answer by Nader Hadji Ghanbari for another approach using Scopes.
Short Answer
By defining a Scope when searching, you can include/exclude arbitrary files/folders from that scope.
Detailed Answer
One way to achieve your requirement (excluding files and folders from a search) is to define a custom scope. This is specifically useful because sometimes you just want to exclude a folder from your search and not from the whole project.
Follow these steps:
Edit -> Find -> Find in path or press Ctrl+Shift+F.
Choose Custom in the Scope section and then choose <unknown scope>
Now click on the + button to add a new local custom scope
Give the scope a name and save it.
Now you can include and exclude directories from this scope. You can first add everything by choosing the include recursively and then exclude one by one by choosing exclude or exclude recursively.
Note that you can even include or exclude libraries your project is dependent on.
When searching you can choose the effective scope by in Scope section in Find in Path dialog.
More info
You can check the JetBrains docs on Scopes for more info. Scopes can be used not only when searching but also in a bunch of other use cases in IntelliJ IDEA.
Patterns
You can use Patterns to define a scope which makes them even more powerful and future proof.
using patterns is another way to exclude files and folders. For instance
file:src/main/java//*&&!file:src/main/java/my//* will exclude all files in my folder.
In Intellij 15, to exclude a folder just do this:
in the Project window, select the folder then right click and choose "Mark Directory As" > "Excluded"
IntelliJ IDEA 2021.3.3 (Ultimate Edition)
In my case, all the generated files in .tox and _build kept showing up in my Find results. It may be a blunt instrument but I added these two folder types to the Preferences -> Editor -> File Types -> Ignored Files and Folders: .tox, _build. For whatever reason, adding _build will not be accepted as part of the ignored set.
Caveat, you will not see these files and folders in your Project navigator. However, it’s a small price to pay for not having them show up consistently in my search results.
A number of answers work well for older versions of IntelliJ, but in 2020.2, and possibly other recent versions, I keep seeing excluded folders in my search results. In my case: node_modules.
I found something that does work, though. For javascript projects, at least. There might be something similar available for other languages.
First, of course, exclude the directory from your project.
Hopefully this works, but if it doesn't, and you're using Javascript, continue:
Go to Settings -> Languages & Frameworks -> Javascript -> Libraries
There, uncheck all the directories you don't want included in your search.
Whether this is a good idea remains to be seen; IntelliJ doesn't merely exclude them from your search, but from all its code parsing, which means it might not recognise imports from that directory either. For me it seems to work fine at the moment, but I give no guarantees. Try it, but remember how to revert this.
It's an ugly work around. IntelliJ clearly needs a better way to exclude directories from searches.
As some have mentioned, simply setting a folder to 'Excluded' doesn't work in many versions. A combination of the following does for me:
Set the offending folder to 'Excluded' as suggested.
Use the pre-defined Scope 'Project Files'
Profit
Excluding files and folders from projects
Article last modified: 08 June 2020
Mark a file as plain text
In the Project tool window, select the desired file.
From the context menu of the selection, choose Mark as plain text:
Exclude files and folders by name patterns
In the Settings/Preferences dialog Ctrl+Alt+S, click Directories .
In the Exclude files field, type the masks that define the names of files and folders to be excluded, for example, *.min.js or lib. Use semicolons as separators.
If the name of a file matches any of these patterns, the file is treated as excluded.
If the name of a folder matches a pattern, all the files in this folder and in its subfolders are excluded.
Source: https://www.jetbrains.com/help/phpstorm/excluding-files-from-project.html
This one the only thing that works for me on IntelliJ 2022.3.1, even when marking directory as excluded didn't work (it only change the icon as red, but still shows up).
File > Preferences > Editor > Ignored Files and Folders
I can ignore the generated bla.html with this.
If you are searching for usages, open the "Find Usages Settings..." , by default Ctrl+Alt+Shift+F7, to narrow down the scope from "All files" to "Project files".
Related
PhpStorm Search Everywhere is not working, do you know the solution?
I don't know this is off topic or not, I'm using general channels. Is there a solution for Search Anywhere in PhpStorm. I work with Laravel but when I use the feature I can't find the file even though it exists.
Looking at your screenshot: based on the fact that ALL files in the project tree have that sort of "dirty yellow" background color... it looks like ALL of your files are considered excluded / outside of the project for some reason. Most likely a user error of some kind. E.g. you may have opened it from a different path (i.e. when symlink is involved), may have c=misconfigured it later somehow (marked folder as Excluded by mistake or whatnot) or maybe even some sort of config file corruption (pretty unlikely). Anyway, please do this: Close your project Go to the project root folder and delete your .idea subfolder (that's where your project settings are stored). If you have that project still visible in the IDE (Recent Projects on the Welcome screen) -- you may remove it there as well (to avoid any possible confusion). Now create a new project in PhpStorm from scratch using existing files: just use "Open" and point to the folder with your project.
Please check filter option. If you are doing file search then click on Files tab.
How to navigate to file in WebStorm if file belongs to excluded folder?
I've excluded vendor folder from indexing. I can navigate to file if it outside of vendor folder with Ctrl + Shift + N but if a file inside the one WebStorm can't find it.
You can try to do an "All" search with double shift. It should appear there if you have ever visited the file. If you haven't opened the file, most probably it will not appear there. The reason for excluding files from indexing is mainly the good performance and marking directories that contain for example build artifacts or libraries to not add noise to your search results. That's why you will not see them.
Hide files from /build directory in navigate class/file action
One of the most productive actions in Android Studio is Navigate action. The problem is it shows so much useless files. Sometimes it's hard to find the class/file you're looking for. Take below image as an example. If you're looking for AndroidManifest.xml in module b you have to scroll down the list to find the file you want. Is there a way to filter what this dialog shows, in particular exclude some directories from results? All of the files from the /build directory are completely useless. I know that I can filter what types of files are shown but it doesn't help much.
Mark your build folder as excluded: File > Project Settings > Modules > Sources > Mark as Excluded (red icon) Alternatively, right click on your build folder and select Mark Directory as > Excluded. Excluded folders (shown as rootExcluded) are ones that IntelliJ IDEA "partially ignores". Very limited coding assistance is provided for files in excluded folders. Classes contained in excluded folders don't appear in code completion suggestion lists, references to such classes are shown in the editor as unresolved. When searching, IntelliJ IDEA doesn't look in excluded folders, etc. Source Another way is to define a custom scope as described here.
How to exclude a file extension from IntelliJ IDEA search?
Is there a way to exclude particular file extension from the results in IntelliJ IDEA's "Find in Path" dialog (invoked by CTRL + SHIFT + F)? I want to exclude all .css files.
In intellij 16 there is a section "File name Filter" to exclude an extension use !*.java. You can give more detailed patterns as well for example I use the pattern below to only return .java files except those with a name starting or ending with test. Pattern: !*test.java,*.java,!Test*.java In recent versions of Intellij the GUI has been updated a bit but the same still applies see the "File mask" on the top right hand corner see image below:
In "Find in Path" and "Find in Files" (Ctrl+Shift+F) you can use the "File mask" input. For example, this would exclude all js, css and twig: !*.js, !*.css, !*.twig It's handy cause it also keeps a list of previous inputs, but it gets messy easily when you add a lot of extensions. If it gets too crowded, consider excluding some folders as well (right-click -> "Mark directory as" -> "Excluded")
You can create custom scope there: In 'Find in Path' dialog you can check radio button 'Custom' and open scopes window. There you can customize path and search pattern. Examples of Patterns for Pattern field: !file:*.css - exclude CSS files file[MyMod]:src/main/java/com/example/my_package//* - include files from the directory in a project. src[MyMod]:com.example.my_package..* - recursively include all files in a package. file:*.js||file:*.coffee - include all JavaScript and CoffeeScript files. file:*js&&!file:*.min.* - include all JavaScript files except those that were generated through minification, which is indicated by the min extension. Or check the official documentation. Good luck!
If you are like me that don't want to use the File Mask option or create a custom scope, etc. but just wanted to be able to add it to project settings one time and be done with it, then here's a solution for you. I wanted my Find in Path to not search in lock files (auto-generated manifest file by package managers), here's what I had to do for that: Goto File >> Project Structure (or just press Command+;) Select Modules under Project Settings Add a pattern or file names to the Exclude files text-box, in this case: *.lock;package-lock.json and hit Apply, and then ok. Note The above option is available in IntelliJ 2019 and versions after that, not sure about older versions. For more info, https://www.jetbrains.com/help/phpstorm/excluding-files-from-project.html
WebStorm 2021 CTRL+SHIFT+F and follow the pictures
For 2019.2, the pattern is not set in scope but in the right top windows "File mask" in Find in path dialog. You must tick it. The syntax I tested are: exclude files with extension css: !*.css exclude all under out dir: !out/* Patterns are separated by comma. Reference: https://www.jetbrains.com/help/idea/finding-and-replacing-text-in-project.html
For 2021.3.2, just right-click to the folder and Mark Directory as -> Excluded. This will work for logs etc but be careful about source folders.
Is it possible to exclude a file from the content root in IntelliJ?
I want to exclude individual .java files from a Content Root in IntelliJ. The documentation on "Excluding Files from Project" suggests that this is not possible (it explicitly says This action is not applicable to Java files and binaries.) Being incredulous to such a limitation, I have tried editing my .iml file, optimistically inserting XML elements such as <excludeFile> under the <content> element, but nothing seems to take. Does anyone know a way to do this (documented or otherwise)? Or have any clue why this feature is not supported? By comparison, Eclipse allows for an arbitrary including pattern for a <classpathentry> element in its .classpath file.
You can exclude files from compilation and classpath. As far as I understand it will have the same effect as manipulating with <classpathentry> in Eclipse. To exclude files/folders by pattern and globally use Ignore files and folders option in the File Types dialog. This way the files will be completely ignored and not visible in the Project View, but it's probably not what you want.