Sublime Forum

How do I find all *.js files in a project?

#1

The fuzzy search in Go To Anything is great but sometimes it is too fuzzy for what I need. For instance, I know I need to open a JavaScript file and that there are only 5 of them somewhere in the project so I’d like to do

Ctrl+P, type .js

and ideally ST2 would give me a list of those files. However, in the results - and on top spots, there are completely unrelated C# files that happen to have “j” and “s” somewhere in their name.

In such cases I would appreciate some way to tell ST2 to use more strict search algorithm, something like enclosing my query in quotes. Is there such “operator” in ST2 or is search always that fuzzy?

0 Likes

#2

Anyone? Or is some plugin needed to achieve this?

0 Likes

#3

Hm. I just tried ‘.js’ and it showed only javascript files. This wasn’t a project though, only a folder. I’ll try a project and see what happens.

EDIT: When I precede ‘js’ with a period, the search does pretty much what I’d expect it to do: it finds the ‘.js’ string in file names, so I got all my javascript files as well as whatever JSON files might be hanging around. Maybe my projects and folders just aren’t varied enough to see what you are seeing.

0 Likes

#4

Interesting. I’m not sure about this one and would like to know as well. Maybe Jon could add an option to disable fuzzy search if the search string contains a *. Sorry I couldn’t be more help.

0 Likes

#5

[quote=“phillip.koebbe”]Hm. I just tried ‘.js’ and it showed only javascript files. This wasn’t a project though, only a folder. I’ll try a project and see what happens.

EDIT: When I precede ‘js’ with a period, the search does pretty much what I’d expect it to do: it finds the ‘.js’ string in file names, so I got all my javascript files as well as whatever JSON files might be hanging around. Maybe my projects and folders just aren’t varied enough to see what you are seeing.[/quote]

Phillip it’s just a coincidence that it works in your project. In ours, the search for .js (including the dot) first returns JsonNetSerializer.cs, then JsonTopGameHelper.cs and only then some JavaScript files. So the search is definitely “too fuzzy” for our use case.

0 Likes

#6

I would suggest adding these two features to the search algorithm:

  • If it’s *.extension (star dot extension), search only for files with a given extension.
  • If it’s “expression” (expression enclosed in quotes) do a strict match (probably still case insensitive though)
0 Likes

#7

[quote=“borekb”]

[quote=“phillip.koebbe”]Hm. I just tried ‘.js’ and it showed only javascript files. This wasn’t a project though, only a folder. I’ll try a project and see what happens.

EDIT: When I precede ‘js’ with a period, the search does pretty much what I’d expect it to do: it finds the ‘.js’ string in file names, so I got all my javascript files as well as whatever JSON files might be hanging around. Maybe my projects and folders just aren’t varied enough to see what you are seeing.[/quote]

Phillip it’s just a coincidence that it works in your project. In ours, the search for .js (including the dot) first returns JsonNetSerializer.cs, then JsonTopGameHelper.cs and only then some JavaScript files. So the search is definitely “too fuzzy” for our use case.[/quote]

I tested your theory by creating files in the root of my project (and this is actually a project) with the names you gave above. I launched Go To Anything and typed ‘.js’ and not only were those files not at the top of the results, they were not in the results at all.

It may still be related to your project (or mine), but I’ve got a hunch it’s more complicated than just file names.

I’m on OS X 10.7.4 and build 2197 if it makes a difference.

0 Likes

#8

@borekb You may have the regex parsed switched on. In Windows Alt-R turns off the parser.

Alternatively, use Ctrl-F (or Find/ Find) and click the Regular Expression button on the far left.

0 Likes

#9

@agibsonsw
He’s talking about ctrl+p.

0 Likes

#10

Strange, I’ve just created a small project to demonstrate the issue and indeed, after typing .js I only see JavaScript files as per your testing. But as soon as I switch to my main project which contains hundreds of files searching for .js returns JsonNetSerializer.cs again.

I’m on build 2195 and can’t try the latest nighly build as I am not a registered user yet (still evaluating ST2). Should I report this as some kind of bug or what do you suggested to do?

0 Likes

#11

[quote=“borekb”]

Strange, I’ve just created a small project to demonstrate the issue and indeed, after typing .js I only see JavaScript files as per your testing. But as soon as I switch to my main project which contains hundreds of files searching for .js returns JsonNetSerializer.cs again.

I’m on build 2195 and can’t try the latest nighly build as I am not a registered user yet (still evaluating ST2). Should I report this as some kind of bug or what do you suggested to do?[/quote]

I went back to 2195 and see the same behavior as I see on 2197. But I have a thought. Have you tried opening the folder and not the project file? I’m wondering if there is something in .sublime-workspace that might be influencing the fuzzy matching. You might try moving the file out of the directory and trying again. If the problematic behavior does not happen, you can scan through the workspace file and see if you can find something that might tip it off. I glanced through mine, but without having those specific files in my project, I don’t know if I could easily identify something that might be contributing to the behavior you are seeing.

0 Likes

#12

Tried with all files copied out of the project, still the same behavior.

Is the Go To Anything search algorithm described anywhere or maybe could developers comment on how it should or should not behave?

0 Likes

#13

[quote=“borekb”]

I would suggest adding these two features to the search algorithm:

  • If it’s *.extension (star dot extension), search only for files with a given extension.
  • If it’s “expression” (expression enclosed in quotes) do a strict match (probably still case insensitive though)[/quote]

Yes this reminds me of Firefox Awesomebar wildcards! I would love to have wildcards in search panel (Ctrl+P, I forget the real name for this) I know using @ already creates a view of the current file and # seems to pull all words (not quite sure what that one does.) Maybe something using the $ symbol should limit by filetype? While we’re at it why not add another that allows you to limit by folder?

Like say

  • $ - limit by filetype

  • % - limit to folder - Example usage %templates would list all files that are within the %templates folder in the project (if say you had multiple folders sharing a name it would show all unless you added more to your search like %.templates)

0 Likes

#14

You can already use a path in your search string. For example, I just opened Go To Anything (CMD-P) and typed ‘spec/models’ and it showed me all the files in the spec/models directory of my project. I will often open a file by typing part of the path as I’m searching, though I rarely use the slashes. For example, If I’m looking for a file with ‘reset’ in the name in the spec/integration folder, I might type ‘specintreset’.

0 Likes