Limit File Search Scope in Sublime Text 2

Sublimetext2Sublimetext

Sublimetext2 Problem Overview


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?

Sublimetext2 Solutions


Solution 1 - Sublimetext2

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"],

Solution 2 - Sublimetext2

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 https://www.sublimetext.com/docs/2/projects.html">source</a>;, works as of ST3 build 3095). But does not work with "binary_file_patterns".

Solution 3 - Sublimetext2

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.

Solution 4 - Sublimetext2

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

Solution 5 - Sublimetext2

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>

Solution 6 - Sublimetext2

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.

See this

Solution 7 - Sublimetext2

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.

  1. Open the Sublime Text > Preferences > Settings - User menu
  2. 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

enter image description here

Solution 8 - Sublimetext2

You can also exclude folders from your search via the Where field:

Where: <open folders>,-*/node_modules/*.*,-*/build/*.*

So in my example above:

  1. I am searching through all Open folders.
  2. I am excluding the folder called "node_modules" which is a top-level folder right under the root directory for my project.
  3. 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).

Solution 9 - Sublimetext2

This solution works perfectly for me : https://superuser.com/a/601270

Find: "something" Where: "<open folders>" // <open folders>" not include hidden folder in sidebar

Solution 10 - Sublimetext2

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"]
            }
        ]
    }

Solution 11 - Sublimetext2

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.

Solution 12 - Sublimetext2

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrickypaiView Question on Stackoverflow
Solution 1 - Sublimetext2AGSView Answer on Stackoverflow
Solution 2 - Sublimetext2JayView Answer on Stackoverflow
Solution 3 - Sublimetext2David PärssonView Answer on Stackoverflow
Solution 4 - Sublimetext2Daniel FlippanceView Answer on Stackoverflow
Solution 5 - Sublimetext2eephillipView Answer on Stackoverflow
Solution 6 - Sublimetext2Harsh VakhariaView Answer on Stackoverflow
Solution 7 - Sublimetext2Kevin LearyView Answer on Stackoverflow
Solution 8 - Sublimetext2afsheeniraniView Answer on Stackoverflow
Solution 9 - Sublimetext2Laurent PerroteauView Answer on Stackoverflow
Solution 10 - Sublimetext2Alter LagosView Answer on Stackoverflow
Solution 11 - Sublimetext2MEngelby777View Answer on Stackoverflow
Solution 12 - Sublimetext2Ahmad AwaisView Answer on Stackoverflow