How do I exclude a folder from search in sublime text 3 permanently?

Viewed 31918

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.

5 Answers

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.

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.

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.

To exclude a sub-folder/sub-directory "folder_exclude_patterns": ["src/file-manager"] worked for me on windows.

Related