Are you working on a large project in Atom? Dozens of directories? Thousands of files? Innumerable node modules? You may have discovered that Atom isn’t the fatest editor out there when executing search queries across an entire project. Give Atom a helping hand by narrowing down the scope of your search with a few simple glob patterns.
- Exclude a directory from your search by adding an exclamation point in front of its name:
- Include or exclude several directories by separating their file paths with commas:
- Search for for a specific file type in all subdirectories:
Note: The trailing slashes are optional - I use them for clarity here to indicate a folder rather than a file.
Every piece of functionality in Atom is provided by a package, and the search panel is no different. When you press Cmd + Shift + F on a Mac or Ctrl + Shift + F on Windows the search panel appears, courtesy of the find-and-replace package. Your search term goes in the first box, and any of the glob patterns in the following tips are placed in the third “File/directory pattern” box.
A glob pattern is a filename that includes wildcard characters. The addition of the wildcard means that the pattern could match more than one path, so
foo*.js could match the files
foobaz.js. A glob pattern may remind you of a regular expression, but doesn’t behave in quite the same way and aren’t as powerful - for example the wildcard
* is equivalent to the regex
1. Exclude gitignored files
Open the Core Settings menu and make sure the Exclude VCS Ignored Paths option is selected. Now every file and directory in your
.gitignore file will be excluded from your search. Typically you would add the
node_modules/ directory in the
2. Search in a specific directory
Do you only want to search for the string “cheezeburger” in the
kittehs/ directory? Then enter this
kittehs/ file path in the Find and Replace panel before hitting return to narrow the search scope to this folder.
3. Search in multiple specific directories
Do you only want to search in either the
kittehs/ folder or the
doge/ folder? Then separate their file paths with a comma to search just within these directories.
4. Exclude specific directories from search
How about when you know you definitely don’t want to search within a particular folder, but want to look everywhere else in the project? Perhaps you don’t want to search within the
tests/ directory for your snippet of code. Perhaps you don’t have a
.gitignore file, or if you do you still need to work with the files and folders listed in it (👋 hello Magento 2 projects and the
It’s possible to exclude a directory from the scope of your search by typing its file path in the 3rd field preceded by an exclamation point.
For example, look everywhere but the
node_modules/ directory by just typing
!node_modules/ and running the search.
5. Include and exclude specific directories
You can combine the previous two techniques by separating your various include and exclude glob patterns with a comma. This is useful if you want to search within a directory but exclude a subdirectory of it, e.g.
6. Search for file types within directories
web/ directory? If we were to type
web/ folder, and not in any of
web/’s subdirectories (if it has any). To include all subdirectories in the search, use the globstar pattern instead:
🌟 Bonus tip
With the keyboard focus in any of the search panel fields, press up ⬆️ and your last search term will appear! You can toggle up and down through your previous terms which is really handy 👐 if you’re searching for the same few terms over and over.
Glob patterns are a useful skill to have in your development ninja toolbelt and will serve you well not only in Atom but in many other editors and search tools, hopefully saving millions of milliseconds of your life when searching for that pesky string. ⏱