junegunn/fzf
Search syntax
In extended-search mode (the default), the user's query is split on whitespace into terms, and each term is interpreted as a small operator. Implemented in src/pattern.go. The README's "Search syntax" section is the user-facing reference; this page focuses on the code.
Operators
| Token | termType (src/pattern.go) |
Algorithm | Description |
|---|---|---|---|
foo |
termFuzzy |
algo.FuzzyMatchV2 (or V1 with --algo=v1) |
Fuzzy match. |
'foo |
termExact |
algo.ExactMatchNaive |
Exact substring match. |
^foo |
termPrefix |
algo.PrefixMatch |
Match must start at position 0. |
foo$ |
termSuffix |
algo.SuffixMatch |
Match must end at the last position. |
'foo$ |
termExactBoundary |
algo.ExactMatchBoundary |
Exact match at a word boundary. |
=foo |
termEqual |
algo.EqualMatch |
Whole-string equality. |
!term |
inverted | (any) | Negation of any of the above. |
| |
OR separator | — | Splits a termSet into multiple OR groups. |
The grammar is documented at the top of src/pattern.go:
// fuzzy
// 'exact
// ^prefix-exact
// suffix-exact$
// !inverse-exact
// !'inverse-fuzzy
// !^inverse-prefix-exact
// !inverse-suffix-exact$Compilation
BuildPattern in src/pattern.go runs the query through these steps:
- Trim whitespace, taking care not to drop trailing escaped spaces (
\). - Look up the cache by string — re-typing the same query is free.
- Split the trimmed query into tokens (
_splitRegexmatches one or more spaces). - For each token:
- Strip the leading
!, setinv. - Strip the leading
',^,=and decide thetermType. - Strip the trailing
$. - If the result is empty, skip.
- Choose the corresponding
algo.AlgofromPattern.procFunand wrap it as aterm.
- Strip the leading
- Group consecutive terms into
termSets, splitting on|.
The result is a Pattern whose MatchItem(item) returns the best (Result, position) tuple across the OR groups, with all AND terms within a group required to match.
Smart case
By default fzf uses smart-case: case-sensitive when the query contains an uppercase letter, otherwise case-insensitive. --ignore-case and --no-ignore-case force the behavior. The decision is made per term in BuildPattern.
Normalization
The default behavior normalizes Latin-script accented characters (so typing ascii matches ãśčíí). --literal disables this. Implemented in src/algo/normalize.go. Disabled per term as well as globally.
Schemes (--scheme)
--scheme selects a preset:
default— general-purpose tuning.path— adds bonus for matches after/; first character of a path component is treated like a word start.history— disables sort and tweaks scoring so that recent (input order) wins ties.
The implementation is a few branches in BuildPattern and a couple of constants in src/algo/algo.go.
Disabled mode
--disabled short-circuits the pattern to a no-op term that matches everything. Useful when fzf is being driven entirely by transform-search actions over --listen.
Where it lives
| Concern | File |
|---|---|
| Query parsing & term grouping | src/pattern.go |
| Algorithm implementations | src/algo/algo.go |
| Normalization tables | src/algo/normalize.go |
| Cache key | Pattern.cacheKey in src/pattern.go |
| Tests | src/pattern_test.go, src/algo/algo_test.go, test/test_filter.rb |
See systems/matching for the broader picture.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.