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

5

120

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.

Millicent answered 31/7, 2017 at 19:22 Comment(4)
Have you tried using folder_exclude_patterns?Counterword
nope trying nowMillicent
Follow-up question: How do I exclude a folder from the sidebar in Sublime Text permanently, specifying it relative to the open folder?Adowa
In Where input append ,<project filters>,-*/<DIR_NAME_TO_EXCLUDE>/Repugnance
O
142

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

Olcott answered 1/8, 2017 at 12:35 Comment(11)
The 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.Skittle
@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.Olcott
-*/node_modules/* previously did not work, but tonight it magically did. "folder_exclude_patterns" hides the folder from the sidebar, but not from searching :/Lungi
@IllyaMoskvin - See https://mcmap.net/q/181547/-how-do-i-exclude-a-folder-from-search-in-sublime-text-3-permanently for how to suppress from Find All while keeping the folders in the side bar.Howbeit
Finally 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.Hatti
No 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 ...Precision
For me it started to work only after restarting the sublime.Pyaemia
We'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.Minnie
"binary_file_patterns": ["**/node_modules/**"] ended up working for me!Sil
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. See my answer, below, for a better solution with binary_file_patterns.Howbeit
Can these exclusion settings be used on a per-Sublime-workspace basis? (eg copied into a .sublime-project file)Whiskey
N
77

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.

Neel answered 7/6, 2018 at 23:13 Comment(6)
This 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?Precision
This worked for me, but ONLY after restarting sublime3, so don't give up....!Crispen
FWIW: 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).Delay
@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.Adowa
@Delay 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.htmlAdowa
I just wrote about how to exclude a directory relative to the project root or open folder's root hereAdowa
H
25

Most of the answers here 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.


To fix this, I went to Sublime Text | Preferences | Settings in the menu, found binary_file_patterns, and added "node_modules/", "coverage/", "tmp/cache/", and .bundle/. For my medium-sized Ruby on Rails project, my painfully slow searches accelerated dramatically:

"binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", 
                         "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip",  
                         "node_modules/", "coverage/", "tmp/cache/", "vendor/bundle/", ".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.

Howbeit answered 18/4, 2019 at 14:44 Comment(7)
For me, this still searches node_modules. Any ideas?Precision
Can you pay that line from your config?Howbeit
Sure, it's "binary_file_patterns": [ ".jpg", ".jpeg", ".png", ".gif", ".ttf", ".tga", ".dds", ".ico", ".eot", ".pdf", ".swf", ".jar", ".zip", "node_modules/", "vendor/*", ".cache_loader/*" ],Precision
Hmm...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" ?Howbeit
No, it does not exclude vendor or .pdf. Just created a file with .pdf extension and it found a string in it. Weird isnt it?Precision
This 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/959Skittle
This was right answer. still showing on sidebar folder. but hide in search.Horvitz
S
14

To exclude any particular file (package.json) or any file type (.scss) or any sub folders (node_modules, assets) from a global folder search in Sublime, you can use the below notation:

E:\X-Author-GDocs-UI, -*/node_modules/*, -*/assets/*, -*.scss, -package.json

enter image description here

Sourdine answered 2/2, 2023 at 11:16 Comment(0)
T
2

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

Trabeated answered 3/1, 2022 at 7:42 Comment(1)
Was just about to give up on this and settle with @Sarath Bade's inline answer but your solution surprisingly worked for me. This is in spite of the fact that the default formatting of my .sublime-project paths was Folder\\Sub folder which I thought made sense replicating in my folder_exclude_patterns declaration. But it seems happy enough with the mismatching - cheersGilgai

© 2022 - 2024 — McMap. All rights reserved.