In Sublime Text, I often use Cmd+P/Ctrl+P to search and jump between files.
Often, it would pick up temporary or cached files like .scssc or things in the /tmp folder.
Is there a way that I can limit what is shown in the search result?
Add and edit this in your ~/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings
file.
// 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"],
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS"],
For Sublime Text 3: To exclude from search and GoTo results, without removing from the sidebar, change the "binary_file_patterns"
setting. Matches files AND folders.
For example, to exclude files in "dist" and "node_modules" from GoTo indexing, add this to your User Settings file:
"binary_file_patterns": ["dist/*", "node_modules/*", "*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"]
I can't figure out how to implement this on a per-project basis :(. Most settings can be moved to a project.sublime-project
file. "Project > Save Project As", save it the root of your project, and add "settings": {...}
to the json in the generated file. (from source, works as of ST3 build 3095). But does not work with "binary_file_patterns".
folder/**
works too. :)
"unused/"
as well as "*/unused/*"
but neither work for me. However, I was able to add an exclude filter like this: -*/unused/*,-*/_sgbak/*
to my search, which is annoying because it doesn't remember, so you have to add it each time.
You can exclude certain file patterns and folders from your project by modifying your project settings like so:
{
"folders":
[
{
"path": "src",
"folder_exclude_patterns": ["backup"]
},
{
"path": "docs",
"file_exclude_patterns": ["*.css"]
}
]
}
This is described in the projects documentation.
You can also exclude folders in the Find All pane by using the -*/foldername/*
syntax in the Where
field - eg:
-*/node_modules/*
http://www.sublimetext.com/forum/viewtopic.php?f=2&t=3847&start=10
where
field.
C:\Projects\SearchThis,-*/but/not/this/*
In sublime text 3 (BLD 3059 Windows) I needed to restrict the "find in folder" function to certain files / folders and maybe a single file,
The following works for me Contents of the where: box
/C/path/2/project/folder,*.c,*.h,-*/path/not/to/look/in,/C/path/2/specific/file/file.h
Taking it further without absolute paths, you can combine the above with the following symbolic locations
<open folders>, <open files>, <current file>
<open folders>,*.c,*.h,-*/never_this_in_folder/*,<open files>
folder_exclude_patterns
and file_exclude_patterns
only hides it from the sidebar, and not from the search or GoTo. Sadly I haven't found any permanent setting for excluding from search and GoTo. So this answer is currently the best workaround.
For SublimeText 2, this is working great for me.
When you choose Find in Files, specify exclude folders in Where input;
-bower_components/**/*, -dist/**/*, -node_modules/**/*, -tmp/**/*
So, a hyphen followed by exclude pattern for folders you don't want to search in.
-folder1/**/*, -folder2/**/*
This will limit your searching scope.
https://i.stack.imgur.com/bHGJq.png
I think many of these answers span a few different versions of Sublime Text, here's how I do this with Sublime Text 3 on a Mac.
Open the Sublime Text > Preferences > Settings - User menu Edit the file_exclude_patterns and folder_exclude_patterns values to ignore files and/or folders from the Find tool
Example
"file_exclude_patterns":
[
".svn",
".git",
".hg",
".md",
".txt",
".DS_Store"
],
"folder_exclude_patterns":
[
"node_modules",
"bower_components",
".svn",
".git",
".hg",
"CVS",
"deprecated",
"cache"
],
Screenshot
https://i.stack.imgur.com/mMeUb.png
node_modules
when doing a folder wide find. However, if you are debugging something and there is an issue with a dependency, it would be nice to have the option to open a file in node_modules
You can also exclude folders from your search via the Where field:
Where: <open folders>,-*/node_modules/*.*,-*/build/*.*
So in my example above:
I am searching through all Open folders. I am excluding the folder called "node_modules" which is a top-level folder right under the root directory for my project. I am excluding the folder called "build" which is a top-level folder right under the root directory for my project.
This works for me in Sublime Text 3 and the folders continue to show in the SideBar. This is a search only exclusion via input (does not affect any behind the scenes indexing).
This solution works perfectly for me : https://superuser.com/a/601270
Find: "something" Where: "<open folders>" // <open folders>" not include hidden folder in sidebar
Just note that if you want to add a subfolder of your project folder, you must to join the folders with \/
. Using the same example of @DavidPärsson:
{
"folders":
[
{
"path": "src",
"folder_exclude_patterns": ["backup\/src\/log"]
}
]
}
For those few times you need to limit the find (and replace) to the current directory only, do this:
c/Path/2/Project,-c/Path/2/Project/*/*
The important bit is /*/*
in the path exclude pattern. Using Sublime Text 3 build 3083 on Windows 7 64-bit.
I think the easiest way to make sure such files and folders are excluded on each project is to just add the following code in Sublime User Settings (Add and edit this in your ~/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings
file.)
{
// Remove certain files permanently from Sublime via Preferences.sublime-settings.
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS", "node_modules"]
}
Gist : https://gist.github.com/ahmadawais/690a816ca158067708ad4dbe17822841
OR you can check my preferences file here https://github.com/ahmadawais/dotFiles/blob/master/SublimeText/User/Preferences.sublime-settings#L80-L81
Success story sharing
binary_file_patterns
removes the files from Goto Anything, but not from Find in Files, as it should based on the comment. Anyone else experiencing this? Know how to fix it? I'm on Ubuntu, build 2221; same thing happens on my Mac (don't know build number)."file_exclude_patterns": ["*.log"]
if you want to ignore certain files rather than folders.