Skip to content

Commit f5060c6

Browse files
authored
Merge pull request #2265 from h-east/update-pattern
Update pattern.{txt,jax}
2 parents 2d56968 + c7d74a0 commit f5060c6

File tree

2 files changed

+84
-57
lines changed

2 files changed

+84
-57
lines changed

doc/pattern.jax

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*pattern.txt* For Vim バージョン 9.1. Last change: 2025 Aug 12
1+
*pattern.txt* For Vim バージョン 9.1. Last change: 2025 Aug 21
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -1477,39 +1477,52 @@ Vim では、'^' と '$' は常に中間の改行にもマッチします。最
14771477
==============================================================================
14781478
11. ファジーマッチ *fuzzy-matching*
14791479

1480-
ファジーマッチとは、不正確な検索文字列を使って文字列を検索することを言います。
1481-
ファジーマッチで、ある文字列がマッチするのは、検索文字列の全ての文字がその文字
1482-
列のどこかに同じ順序で存在する場合です。大文字小文字は無視されます。マッチした
1483-
文字列では、検索文字列内で隣り合う2文字の間に他の文字が存在するかもしれません。
1484-
検索文字列が複数の単語を持つ場合、各単語は別々にマッチします。そのため検索文字
1485-
列内の複数の単語は{訳注: マッチした}文字列内でどのような順序でも存在し得ます。
1480+
ファジーマッチは、パターン文字が必ずしも連続して出現するとは限らない場合に、文
1481+
字列がパターンにどの程度マッチするかをスコア付けする。
14861482

1487-
Vim は fzy プロジェクトと同じ改良されたアルゴリズムを使用します:
1483+
例: >
1484+
パターン: "vim"
1485+
候補: "vim" -> 完璧
1486+
"vimeo" -> 良い (v i m)
1487+
"voice mail" -> 弱い (v _ i _ _ _ m)
1488+
"vintage" -> マッチしない (no "m")
1489+
<
1490+
検索文字列に複数の単語が含まれている場合、各単語は個別にマッチし、候補リスト内
1491+
で任意の順序で出現する可能性がある。例えば、"get pat" は "GetPattern"、
1492+
"PatternGet"、"getPattern"、"patGetter"、"getSomePattern"、"MatchpatternGet"
1493+
などとマッチする。
1494+
1495+
'ignorecase' および 'smartcase' オプションは適用されず、パターンがすべて小文字
1496+
の場合、大文字/小文字は無視される。
1497+
1498+
Vim の実装は、fzy プロジェクトのアルゴリズムに基づいている:
14881499
https://github.com/jhawthorn/fzy
14891500

1490-
ファジーマッチではマッチした文字列ごとに以下の基準に基づいてスコアが割り当てら
1491-
れます:
1492-
- 連続してマッチした文字の個数。
1493-
- 検索文字列内で隣り合う2文字の間の文字の個数 (距離)。
1494-
- 単語の先頭でのマッチ
1495-
- キャメルケース文字でのマッチ (例えば CamelCase の Case)
1496-
- パスの区切り文字またはハイフンの後ろでのマッチ
1497-
- {訳注: マッチした}文字列内のマッチしなかった文字の個数。
1498-
- 完全/正確なマッチが推奨される。
1499-
マッチした文字列でスコアが最も高かったものが最初に返されます。
1500-
1501-
例えば "get pat" という文字列をファジーマッチで検索すると、"GetPattern"、
1502-
"PatternGet"、"getPattern"、"patGetter"、"getSomePattern"、"MatchpatternGet"
1503-
などの文字列がマッチします。
1501+
与えられたパターンと候補に対して、動的計画法を用いて最適なスコアを計算する。
1502+
1503+
アルゴリズムは 2 段階で動作する:
1504+
1505+
1. 前方パス
1506+
候補を左から右にスキャンし、各パターンの位置における最高スコアを追跡する。
1507+
マッチは、候補の先頭、単語の先頭 (スペース、アンダースコア、ダッシュ、キャ
1508+
メルケース)、または直前のマッチの直後に出現すると、より高いスコアになる。
1509+
1510+
2. 後方パス
1511+
最高得点の終了位置から開始し、一歩下がってマッチする位置を見つけ、配置が最
1512+
適であることを確認する。
1513+
1514+
Vim はオリジナルのアルゴリズムを拡張し、マルチバイトコードポイントをサポートす
1515+
ることで、UTF-8 やその他のエンコーディングでの正確なマッチングを可能にした。
1516+
1517+
計算時間は O (パターン * 候補) である。メモリ使用量もこれに比例する。
15041518

1505-
関数 |matchfuzzy()||matchfuzzypos()| で文字列のリストに含まれる文字列をファ
1506-
ジー検索できます。関数 matchfuzzy() はマッチした文字列のリストを返します。関数
1507-
matchfuzzypos() はマッチのリスト、マッチの位置およびファジーマッチのスコアを返
1508-
します。
1519+
|matchfuzzy()| 関数と |matchfuzzypos()| 関数は、文字列のリスト内でファジー検索
1520+
を実行する。|matchfuzzy()| はマッチする文字列を返し、|matchfuzzypos()| はマッ
1521+
チする文字列をその位置とスコアとともに返す。
15091522

1510-
`:vimgrep` の フラグ "f" はファジーマッチを有効にします
1523+
`:vimgrep` の フラグ "f" はファジーマッチを有効にする
15111524

15121525
|ins-completion| のファジーマッチを有効にするには、'completeopt' オプションに
1513-
"fuzzy" 値を追加します
1526+
"fuzzy" 値を追加する
15141527

15151528
vim:tw=78:ts=8:noet:ft=help:norl:

en/pattern.txt

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*pattern.txt* For Vim version 9.1. Last change: 2025 Aug 12
1+
*pattern.txt* For Vim version 9.1. Last change: 2025 Aug 21
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1501,37 +1501,51 @@ Finally, these constructs are unique to Perl:
15011501
==============================================================================
15021502
11. Fuzzy matching *fuzzy-matching*
15031503

1504-
Fuzzy matching refers to matching strings using a non-exact search string.
1505-
Fuzzy matching will match a string, if all the characters in the search string
1506-
are present anywhere in the string in the same order. Case is ignored. In a
1507-
matched string, other characters can be present between two consecutive
1508-
characters in the search string. If the search string has multiple words, then
1509-
each word is matched separately. So the words in the search string can be
1510-
present in any order in a string.
1504+
Fuzzy matching scores how well a string matches a pattern when the pattern
1505+
characters appear in order but not necessarily contiguously.
15111506

1512-
Vim uses the same improved algorithm as the fzy project:
1507+
Example: >
1508+
Pattern: "vim"
1509+
Candidates: "vim" -> perfect
1510+
"vimeo" -> good (v i m)
1511+
"voice mail" -> weaker (v _ i _ _ _ m)
1512+
"vintage" -> no match (no "m")
1513+
<
1514+
If the search string has multiple words, each word is matched separately and
1515+
may appear in any order in the candidate. For example "get pat" matches
1516+
"GetPattern", "PatternGet", "getPattern", "patGetter", "getSomePattern",
1517+
"MatchpatternGet", etc.
1518+
1519+
The 'ignorecase' and 'smartcase' options do not apply, case is ignored if the
1520+
pattern is all lower case.
1521+
1522+
Vim's implementation is based on the algorithm from the fzy project:
15131523
https://github.com/jhawthorn/fzy
15141524

1515-
Fuzzy matching assigns a score for each matched string based on the following
1516-
criteria:
1517-
- The number of sequentially matching characters.
1518-
- The number of characters (distance) between two consecutive matching
1519-
characters.
1520-
- Matches at the beginning of a word
1521-
- Matches at a camel case character (e.g. Case in CamelCase)
1522-
- Matches after a path separator or a hyphen.
1523-
- The number of unmatched characters in a string.
1524-
- A full/exact match is preferred.
1525-
The matching string with the highest score is returned first.
1526-
1527-
For example, when you search for the "get pat" string using fuzzy matching, it
1528-
will match the strings "GetPattern", "PatternGet", "getPattern", "patGetter",
1529-
"getSomePattern", "MatchpatternGet" etc.
1530-
1531-
The functions |matchfuzzy()| and |matchfuzzypos()| can be used to fuzzy search
1532-
a string in a List of strings. The matchfuzzy() function returns a List of
1533-
matching strings. The matchfuzzypos() functions returns the List of matches,
1534-
the matching positions and the fuzzy match scores.
1525+
It uses dynamic programming to compute an optimal score for a given pattern
1526+
and candidate.
1527+
1528+
The algorithm works in two stages:
1529+
1530+
1. Forward pass
1531+
Scan the candidate left to right, tracking the best score for each
1532+
pattern position. Matches score higher when they occur at the start
1533+
of the candidate, the start of a word (space, underscore, dash,
1534+
camelCase), or directly after the previous match.
1535+
1536+
2. Backward pass
1537+
Start from the best-scoring end position and step back to find match
1538+
positions, ensuring the alignment is optimal.
1539+
1540+
Vim extends the original algorithm to support multibyte codepoints, allowing
1541+
correct matching for UTF-8 and other encodings.
1542+
1543+
Time complexity is O(pattern * candidate). Memory usage is proportional
1544+
to the same.
1545+
1546+
The |matchfuzzy()| and |matchfuzzypos()| functions perform fuzzy searching in
1547+
a List of strings. |matchfuzzy()| returns the matching strings, while
1548+
|matchfuzzypos()| returns the matches along with their positions and scores.
15351549

15361550
The "f" flag of `:vimgrep` enables fuzzy matching.
15371551

0 commit comments

Comments
 (0)