globs.md

 1---
 2title: Glob Patterns - Zed
 3description: How glob patterns work in Zed for file matching, search filtering, and configuration. Syntax reference and examples.
 4---
 5
 6# Globs
 7
 8Zed supports the use of [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns that are the formal name for Unix shell-style path matching wildcards like `*.md` or `docs/src/**/*.md` supported by sh, bash, zsh, etc. A glob is similar but distinct from a [regex (regular expression)](https://en.wikipedia.org/wiki/Regular_expression). In Zed, globs are commonly used when matching filenames.
 9
10## Glob Flavor
11
12Zed uses two different rust crates for matching glob patterns:
13
14- [ignore crate](https://docs.rs/ignore/latest/ignore/) for matching glob patterns stored in `.gitignore` files
15- [glob crate](https://docs.rs/glob/latest/glob/) for matching file paths in Zed
16
17While simple expressions are portable across environments (e.g. running `ls *.py` or `*.tmp` in a gitignore) there is significant divergence in the support for and syntax of more advanced features varies (character classes, exclusions, `**`, etc) across implementations. For the rest of this document we will be describing globs as supported in Zed via the `glob` crate implementation. Please see [References](#references) below for documentation links for glob pattern syntax for `.gitignore`, shells and other programming languages.
18
19The `glob` crate is implemented entirely in rust and does not rely on the `glob` / `fnmatch` interfaces provided by your platforms libc. This means that globs in Zed should behave similarly with across platforms.
20
21## Introduction
22
23A glob "pattern" is used to match a file name or complete file path. For example, when using "Search all files" {#kb project_search::ToggleFocus} you can click the funnel shaped Toggle Filters" button or {#kb project_search::ToggleFilters} and it will show additional search fields for "Include" and "Exclude" which support specifying glob patterns for matching file paths and file names.
24
25### Multiple Patterns
26
27You can specify multiple glob patterns in Project Search filters by separating them with commas. When using comma-separated patterns, Zed correctly handles braces within individual patterns:
28
29- `*.ts, *.tsx` — Match TypeScript and TSX files
30- `src/{components,utils}/**/*.ts, tests/**/*.test.ts` — Match TypeScript files in specific directories plus test files
31
32Each pattern is evaluated independently. Commas inside braces (like `{a,b}`) are treated as part of the pattern, not as separators.
33
34**Important:** While braces are preserved in patterns, Zed does not expand them into multiple patterns. The pattern `src/{a,b}/*.ts` matches the literal path structure, not `src/a/*.ts` OR `src/b/*.ts`. This differs from shell behavior.
35
36When creating a glob pattern you can use one or multiple special characters:
37
38| Special Character | Meaning                                                           |
39| ----------------- | ----------------------------------------------------------------- |
40| `?`               | Matches any single character                                      |
41| `*`               | Matches any (possibly empty) sequence of characters               |
42| `**`              | Matches the current directory and arbitrary subdirectories        |
43| `[abc]`           | Matches any one character in the brackets                         |
44| `[a-z]`           | Matches any of a range of characters (ordered by Unicode)         |
45| `[!...]`          | The negation of `[...]` (matches a character not in the brackets) |
46
47Notes:
48
491. Brace characters `{` and `}` are literal pattern characters, not expansion operators. The pattern `src/{a,b}/*.ts` matches paths containing the literal text `{a,b}`, not paths matching either `src/a/*.ts` or `src/b/*.ts` as in shell globbing.
502. To match a literal `-` character inside brackets it must come first `[-abc]` or last `[abc-]`.
513. To match the literal `[` character use `[[]` or put it as the first character in the group `[[abc]`.
524. To match the literal `]` character use `[]]` or put it as the last character in the group `[abc]]`.
53
54## Examples
55
56### Matching file extensions
57
58If you wanted to only search Markdown files add `*.md` to the "Include" search field.
59
60### Case insensitive matching
61
62Globs in Zed are case-sensitive, so `*.c` will not match `main.C` (even on case-insensitive filesystems like HFS+/APFS on macOS). Instead use brackets to match characters. So instead of `*.c` use `*.[cC]`.
63
64### Matching directories
65
66If you wanted to search the [zed repository](https://github.com/zed-industries/zed) for examples of [Configuring Language Servers](https://zed.dev/docs/configuring-languages#configuring-language-servers) (under `"lsp"` in Zed settings.json) you could search for `"lsp"` and in the "Include" filter specify `docs/**/*.md`. This would only match files whose path was under the `docs` directory or any nested subdirectories `**/` of that folder with a filename that ends in `.md`.
67
68If instead you wanted to restrict yourself only to [Zed Language-Specific Documentation](https://zed.dev/docs/languages) pages you could define a narrower pattern of: `docs/src/languages/*.md` this would match [`docs/src/languages/rust.md`](https://github.com/zed-industries/zed/blob/main/docs/src/languages/rust.md) and [`docs/src/languages/cpp.md`](https://github.com/zed-industries/zed/blob/main/docs/src/languages/cpp.md) but not [`docs/src/configuring-languages.md`](https://github.com/zed-industries/zed/blob/main/docs/src/configuring-languages.md).
69
70### Implicit Wildcards
71
72When using the "Include" / "Exclude" filters on a Project Search each glob is wrapped in implicit wildcards. For example to exclude any files with license in the path or filename from your search just type `license` in the exclude box. Behind the scenes Zed transforms `license` to `**license**`. This means that files named `license.*`, `*.license` or inside a `license` subdirectory will all be filtered out. This enables users to easily filter for `*.ts` without having to remember to type `**/*.ts` every time.
73
74Alternatively, if in your Zed settings you wanted a [`file_types`](./reference/all-settings.md#file-types) override which only applied to a certain directory you must explicitly include the wildcard globs. For example, if you had a directory of template files with the `html` extension that you wanted to recognize as Jinja2 template you could use the following:
75
76```json [settings]
77{
78  "file_types": {
79    "C++": ["[cC]"],
80    "Jinja2": ["**/templates/*.html"]
81  }
82}
83```
84
85## References
86
87While globs in Zed are implemented as described above, when writing code using globs in other languages, please reference your platform's glob documentation:
88
89- [macOS fnmatch](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fnmatch.3.html) (BSD C Standard Library)
90- [Linux fnmatch](https://www.gnu.org/software/libc/manual/html_node/Wildcard-Matching.html) (GNU C Standard Library)
91- [POSIX fnmatch](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html) (POSIX Specification)
92- [node-glob](https://github.com/isaacs/node-glob) (Node.js `glob` package)
93- [Python glob](https://docs.python.org/3/library/glob.html) (Python Standard Library)
94- [Golang glob](https://pkg.go.dev/path/filepath#Match) (Go Standard Library)
95- [gitignore patterns](https://git-scm.com/docs/gitignore) (Gitignore Pattern Format)
96- [PowerShell: About Wildcards](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards) (Wildcards in PowerShell)