How do I exclude a folder from search in sublime text 3 permanently?
Solution 1
Go to the Settings menu and in the Preferences.sublime-settings
file for the user and add a new node to the json named folder_exclude_patterns
. In it, add the folders that you don't want to be displayed (in json array format).
Example:
{
// ... other settings
"folder_exclude_patterns": ["node_modules", "another_folder"],
}
If you want to exclude certain directory or file without hiding it from the sidebar, you can ignore the above solution and Add Exclude Filter
in the Where
section of the search bar. But you will have to specify it everytime you change the search directory.
Note: You might need to restart Sublime Text in order to see the changes, as mentioned by @Soferio
Solution 2
If you go to the Preferences menu and then select Settings, it will open a JSON file of all the settings and their default values. This file also serves as documentation for what the settings mean. Two of them are relevant here. Here's the snippet from the Settings JSON file (last verified in Sublime Text 4):
// folder_exclude_patterns and file_exclude_patterns control which files
// are listed in folders on the side bar. These can also be set on a per-
// project basis.
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS", ".Trash", ".Trash-*"],
"file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", ".directory", "desktop.ini", "*.class", "*.psd", "*.db", "*.sublime-workspace"],
// These files will still show up in the side bar, but won't be included in
// Goto Anything or Find in Files
"binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
It says here that "folder_exclude_patterns"
hides it from the side bar, while "binary_file_patterns"
hides it from search (these "won't be included in Goto Anything or Find in Files"). So if you want to exclude it from both, you can open the User Settings file, which overrides the default settings, and add the following.
Note that the User Settings file is what you see and can edit in the right-hand pane when you go to Preferences --> Settings.
Anyway, add the following:
{
"folder_exclude_patterns": ["node_modules"],
"binary_file_patterns": ["*/node_modules/*"]
}
The two entries above are different because the former is a folder pattern while the latter is a file pattern.
Solution 3
I added "node_modules/", "coverage/", "tmp/cache/"
to binary_file_patterns
for my medium-sized Ruby on Rails project to speed up my painfully slow searches:
"binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds",
"*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip",
"node_modules/", "coverage/", "tmp/cache/", "vendor/bundle/"],
Before, Find All In Files took about 7 seconds:
Searching 28526 files for "as records_with_errors"
After, Find All In Files takes less than 1 second:
Searching 1658 files for "as records_with_errors"
I added coverage
not for performance, but to prevent redundant, useless search results.
BTW, most of the solutions I've found to this problem focus on folder_exclude_patterns
, and overlook that binary_file_patterns
can specify folder patterns, probably due to its name and Sublime's default settings for it.
Using folder_exclude_patterns
is NOT a clean solution for the OP is looking for. The fact that it hides folders from the side bar will certainly make you challenge your sanity when someday you do go looking for those files and they simply don't exist.
That concern applies also to the suppression of Find results, of course, which should be weighed carefully before blocking too many folders. Only include folders/patterns which you actively want to suppress...don't include things you simply think you won't need to search if they're not causing you problems.
Solution 4
These are correct solutions, but you must restart Sublime3 for the changed configuration to take hold. Don't just close windows, QUIT the entire application.
Solution 5
To exclude a sub-folder/sub-directory "folder_exclude_patterns": ["src/file-manager"]
worked for me on windows.
nolawi
I am a javascript developer. I love accessibility and design systems.
Updated on February 09, 2022Comments
-
nolawi about 2 years
is there a way to always ignore a folder... in project view.
I have multiple apps in one repo and have 'node_modules' in each app
mainapp ├── microapp │ └── node_modules ├── microapp2 │ └── node_modules ├── index ├── config └── assets
I want to exclude from search the
node_modules
folder when i search inside project in the above structure. -
Illya Moskvin about 6 yearsThe problem with this approach is that it not only excludes these folders from search, but also from the sidebar, which isn't always desirable. I'm still looking for a reliable solution that doesn't nuke the sidebar.
-
SUB0DH about 6 years@IllyaMoskvin I've updated the answer to add some of your desired solution, but it won't be a permanent one. Maybe it is possible through some third party plugins.
-
Jakob Jingleheimer about 6 years
-*/node_modules/*
previously did not work, but tonight it magically did."folder_exclude_patterns"
hides the folder from the sidebar, but not from searching :/ -
David Hempy almost 5 years@IllyaMoskvin - See stackoverflow.com/a/55748485/4454732 for how to suppress from Find All while keeping the folders in the side bar.
-
Luis Febro over 4 yearsFinally what really worked and excluded a vast undesirable search results was inserting
-*/node_modules/*
as suggested by @jacob. My previous search was about 20.000 files and dropped to about 80 of them. -
trainoasis over 4 yearsNo one has a solution for excluding the folder from search/replaces permanently? Don't wanna always have to add node_modules manually - it defeats the purpose of saving time not searching the whole node_modules ...
-
trainoasis over 4 yearsFor me, this still searches node_modules. Any ideas?
-
trainoasis over 4 yearsThis seems like the correct answer, but for me it still searches node_modules/ and vendor/ it seems, number of files searched is the same. Any ideas?
-
David Hempy over 4 yearsCan you pay that line from your config?
-
trainoasis over 4 yearsSure, it's "binary_file_patterns": [ ".jpg", ".jpeg", ".png", ".gif", ".ttf", ".tga", ".dds", ".ico", ".eot", ".pdf", ".swf", ".jar", ".zip", "node_modules/", "vendor/*", ".cache_loader/*" ],
-
David Hempy over 4 yearsHmm...that seems to match what I've got locally exactly. Can you confirm it suppresses results from some of your other exclusions, such as "vendor/*" or ".pdf" ?
-
trainoasis over 4 yearsNo, it does not exclude vendor or .pdf. Just created a file with .pdf extension and it found a string in it. Weird isnt it?
-
Borys Pylhun over 4 yearsFor me it started to work only after restarting the sublime.
-
Illya Moskvin over 4 yearsThis method only works if the "Where" field in the "Find in Files" panel does not include a folder. If that field contains a directory (e.g. if you right-click in sidebar and choose "Find in Folder"),
binary_file_patterns
will not work. Here's the issue: github.com/sublimehq/sublime_text/issues/959 -
Jacob Ford over 4 yearsWe've got it! It's the
binary_file_patterns
array in Sublime Settings. This tells Goto Anything (⌘+T) to ignore these files. Note that the syntax is a little different as you're now matching files, not folders. -
Soferio over 4 yearsThis worked for me, but ONLY after restarting sublime3, so don't give up....!
-
Chris Whalen over 3 years
"binary_file_patterns": ["**/node_modules/**"]
ended up working for me! -
David Hempy over 3 yearsUsing folder_exclude_patterns is NOT a clean solution for the OP is looking for. The fact that it hides folders from the side bar will certainly make you challenge your sanity when someday you do go looking for those files and they simply don't exist. See my answer, below, for a better solution with
binary_file_patterns
. -
smhg over 2 yearsFWIW: this can also be applied on a per-project basis inside your
[project].sublime-project
file for each individual folder listed in there (so it should be on the same level as a"path"
property). -
Gabriel Staples about 2 years@smhg, thank you thank you thank you! That's the secret! It must be at the same level as the
"path"
entry. I had it one level up, at the"folders"
entry, and that doesn't work. -
Gabriel Staples about 2 years@smhg and anyone else wondering: there is an example of where to place
"folder_exclude_patterns"
in Project settings in the official documentation here: sublimetext.com/docs/projects.html -
Gabriel Staples about 2 years
-
Ben Aston about 2 yearsCan these exclusion settings be used on a per-Sublime-workspace basis? (eg copied into a
.sublime-project
file)