Limit File Search Scope in Sublime Text 2

你离开我真会死。 提交于 2019-12-29 10:08:43

问题


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?


回答1:


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



回答2:


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".




回答3:


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.




回答4:


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




回答5:


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>



回答6:


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.




回答7:


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




回答8:


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).




回答9:


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

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



回答10:


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.




回答11:


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



回答12:


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



来源:https://stackoverflow.com/questions/13706965/limit-file-search-scope-in-sublime-text-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!