Limit File Search Scope in Sublime Text 2

2019-01-29 15:00发布

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?

12条回答
Viruses.
2楼-- · 2019-01-29 15:25

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.

查看更多
做个烂人
3楼-- · 2019-01-29 15:29

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

查看更多
萌系小妹纸
4楼-- · 2019-01-29 15:30

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"],
查看更多
该账号已被封号
5楼-- · 2019-01-29 15:30

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

查看更多
做个烂人
6楼-- · 2019-01-29 15:30

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

查看更多
甜甜的少女心
7楼-- · 2019-01-29 15:37

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>
查看更多
登录 后发表回答