Skip to content

Commit 0ac1eb3

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1311: completion: not possible to limit number of matches
Problem: completion: not possible to limit number of matches Solution: allow to limit the matches for 'complete' sources by using the "{flag}^{limit}" notation (Girish Palya) This change extends the 'complete' option to support limiting the number of matches returned from individual completion sources. **Rationale:** In large files, certain sources (such as the current buffer) can generate an overwhelming number of matches, which may cause more relevant results from other sources (e.g., LSP or tags) to be pushed out of view. By specifying per-source match limits, the completion menu remains balanced and diverse, improving visibility and relevance of suggestions. A caret (`^`) followed by a number can be appended to a source flag to specify the maximum number of matches for that source. For example: ``` :set complete=.^9,w,u,t^5 ``` In this configuration: - The current buffer (`.`) will return up to 9 matches. - The tag completion (`t`) will return up to 5 matches. - Other sources (`w`, `u`) are not limited. This feature is fully backward-compatible and does not affect behavior when the `^count` suffix is not used. The caret (`^`) was chosen as the delimiter because it is least likely to appear in file names. closes: #17087 Signed-off-by: Girish Palya <girishji@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 1c2b258 commit 0ac1eb3

File tree

7 files changed

+341
-56
lines changed

7 files changed

+341
-56
lines changed

runtime/doc/options.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Apr 15
1+
*options.txt* For Vim version 9.1. Last change: 2025 Apr 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2125,6 +2125,13 @@ A jump table for the options with a short description can be found at |Q_op|.
21252125
based expansion (e.g., dictionary |i_CTRL-X_CTRL-K|, included patterns
21262126
|i_CTRL-X_CTRL-I|, tags |i_CTRL-X_CTRL-]| and normal expansions).
21272127

2128+
An optional match limit can be specified for a completion source by
2129+
appending a caret ("^") followed by a {count} to the source flag.
2130+
For example: ".^9,w,u,t^5" limits matches from the current buffer
2131+
to 9 and from tags to 5. Other sources remain unlimited.
2132+
The match limit takes effect only during forward completion (CTRL-N)
2133+
and is ignored during backward completion (CTRL-P).
2134+
21282135
*'completefunc'* *'cfu'*
21292136
'completefunc' 'cfu' string (default: empty)
21302137
local to buffer

runtime/doc/version9.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Apr 15
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Apr 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41622,6 +41622,8 @@ Completion: ~
4162241622
"f{func}" - complete using given function
4162341623
"f" - complete using 'completefunc'
4162441624
"o" - complete using 'omnifunc'
41625+
- allow to limit matches for the 'complete' sources by using the
41626+
"{flag}^<limit>" notation
4162541627

4162641628
Options: ~
4162741629
- the default for 'commentstring' contains whitespace padding to have

0 commit comments

Comments
 (0)