Sublime Forum

Exclude folders from search but show in side bar

#1

Is there any way to exclude files/folder from be parsed in project wide searches (go to anything, find files files) but have those files/folder still show up in the sidebar? For example I use NodeJS and therefore I have a node_modules folders and most of the time I don’t need look at those files but there are times when I do. I know I can exclude those files from searches and from the sidebar however being able to remove them just from searches would be very helpful.

2 Likes

#2

I had a similar question. I want to exclude a certain directory from being searched, but using -./directory/ does not work, or I have to add -./directory/subdir/*.rs for every subdir.

Am I missing something?

0 Likes

#3

I’d also really like to figure out how to do this…I’ve done a bit of searching and it seems like ST3 just doesn’t have this capability. Anyone out there figure out how to exclude a folder from Search and Go To Anything but still display it in the sidebar?

0 Likes

#4

+1

0 Likes

#5

+1

0 Likes

#6

Possibly relevant: folder_exclude_patterns but show in sidebar?

0 Likes

#7

Use the binary_file_patterns setting, as explained in the thread linked by @QED1224.

3 Likes

#8

Ok, i agreed with you and convince to you anyone out there figure out how to exclude a folder from Search and Go To Anything but still display it in the sidebar?

0 Likes

#9

not the same. Here the Op talks about folders not files

0 Likes

#10

I am talking about an sub folder, not the all the file of some kind. So binary_file_pattern is probably not the answer.

Anyone figure it out yet? To exclude searching a specific directory?

0 Likes

#11

Really, binary_file_patterns will exclude files and folders from Goto Anything and Find in Files. You would just place the folder name you want to ignore in the list, e.g.:

"binary_file_patterns": ["node_modules/", "*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],

Try it!

6 Likes

#12

It doesn’t work. I put it in my projects settings:

{
  "folders":
    [
      {
        "path": "/path_to_project",
        "folder_exclude_patterns": ["tmp", ".idea" ],
        "binary_file_patterns": ["log/", "*.sqlite3", "*.sql", "public/assets/"]
      }
    ]
}

Sublime Text 3 Build 3126

0 Likes

#13

you have to put binary_file_patterns in your user settings:

1 Like

#14

Maybe I’m doing something wrong, but putting it in user settings doesn’t work also.

I’ve tried:

  "settings": {
  	"binary_file_patterns": ["log/", "*.sqlite3", "*.sql", "public/assets/"]
  }

as well as

  "binary_file_patterns": ["log/", "*.sqlite3", "*.sql", "public/assets/"]
0 Likes

#15

The setting needs to be placed in your Packages/User/Preferences.sublime-settings file (right-hand pane of the Preferences > Settings menu item). It is not currently supported in a .sublime-project file.

Settings are never placed in a settings key of a .sublime-settings file. That is only used to place settings in a .sublime-project file, and as mentioned above, binary_file_patterns is currently not supported there.

4 Likes

#16

Thanks for reply.
But still the same. I check it with “Find in files” and get results from js files in public/assets/.

0 Likes

#17

Find in Files is sensitive to what the Where: field is set to during the search, which can be a bit counter-intuitive when you’re not used to it.

Here’s a small project containing two identical files in a project with settings set to treat anything in public/assets/ as binary. If I search for text that appears in both files, I get two results even though one of the files is in the path that is supposed to be excluded:

The reason for this is that because the Where: field is blank, it is defaulting to “Open files and folders” (visible as light gray text). The file that we want to be excluded is open, so it gets searched even though its path is in the list of exclusions. This makes logical sense; although we told sublime to ignore everything in that folder as binary, we have it open AND told it to search open files, so it makes sense that it would search in that file.

If you instead modify the Where: field to be just Open Folders (all folders in the project), which you can get at from the ellipsis menu to the right of the Where: field, the same search properly excludes the file that is in the path as we might expect, even if it’s open:

Here’s where things get a little bit strange. I don’t know if this is a bug or expected behaviour (perhaps @wbond can verify?) but if the Where: field is set to an explicit path, then it will still also find files that match the contents of the binary_file_patterns setting, even though you would think that it would not:

This bit seems wrong to me, as in this case you’re telling Sublime to search all files in a given path, but you’ve also told it that certain files are binary and it still finds them anyway. This is particularly annoying if you happen to use a search term that matches the contents of a truly binary file like a PNG.

5 Likes

How do I exclude folder and all subfolders from search?
#18

First, thank you for your help.

I have to admit I haven’t try the “binary_file_patterns” solution out. It might be working, but, correct me if I am wrong, that solution doesn’t fit my scenario. I just want to exclude it from a specific search. So I want to specify in the “where” text field, that I want to search all files inside directory but not inside it’s subdirectory this time. And may be in the next search I still want to search the subdirectory.

To explain further, I used to search file in a directory and type “/src/” to search text file inside it, and then I have discover that the “noise” directory had many unrelated information, and I don’t want to search inside it. So I type “/src/, -/noise/” in the “Where” text field. But that doesn’t work, the file that satisfy “/src/” or “-/noise/” is the target to be search. But what I want is to search files that satisfy both.

The point is, sometimes I want to search files that satisfy both of the pattern, and sometimes I want to search files that satisfy either of the pattern. And to go further, I might want to combine more conditions that mix conditions such as “pattern1” and (“pattern2” or “pattern3”), and using it in the where text field, but not to exclude a patterns from Goto Anything, just use it one or several times.

Oh, I have come back to this post after a long time, and after I reread the post I found that my scene and poster scene are quite different.

1 Like

#19

surely /src/ would satisfy both? or does ST do fuzzy matching? in which case, try /src/,-/src/noise/

1 Like

#20

It would be really useful to see binary_file_patterns supported in project files. Different projects have different exclusions, and it would be very handy to store what those are at the project level rather than just in the UI.

3 Likes