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.