[vim/vim] fix(completion): when only fuzzy no completion insert (PR #14976)

55 views
Skip to first unread message

glepnir

unread,
Jun 12, 2024, 10:08:29 AMJun 12
to vim/vim, Subscribed

initial attempt we can generate a fuzzy matching regular expression here and give it to searchit. then keyword completion CTRL-N CTRL-P can get a fuzzy result and set into match array. currently multi-byte characters need to be processed

Fix #14912


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/14976

Commit Summary

  • 3f53ee8 fix(completion): when only fuzzy no completion insert

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976@github.com>

Christian Brabandt

unread,
Jun 12, 2024, 2:29:58 PM (14 days ago) Jun 12
to vim/vim, Subscribed

I am not sure we should go this way. I thought the idea is to generate the list of candidates normally (without considering fuzzy) and apply the fuzzying only once the completion list has been show to reduce the number of items shown in the popup? So after the completion menu has been shown with all matches initially?

Otherwiese I am not sure it makes sense for completion methods like thesaurus completion, whole line completion, dictionary, spelling or tags completion. In the end, that's why we have different completion methods for and if you want to gather a list of completions using fuzzy matching, one can omni-completion or user-defined completion.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2163663412@github.com>

Maxim Kim

unread,
Jun 12, 2024, 9:50:41 PM (14 days ago) Jun 12
to vim/vim, Subscribed

It actually makes sense to apply fuzzy initially when gathering completion candidates as well. At least I would expect it to happen. Also #14921


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2164201200@github.com>

glepnir

unread,
Jun 13, 2024, 2:20:05 AM (13 days ago) Jun 13
to vim/vim, Subscribed

removing edit on get_normal_compl_info will fix the problem of keyword not being completed when completeopt set fuzzy but doesn't include menu/menuone.

I am not sure we should go this way. I thought the idea is to generate the list of candidates normally (without considering fuzzy) and apply the fuzzying only once the completion list has been show to reduce the number of items shown in the popup? So after the completion menu has been shown with all matches initially?

Internally we differentiate between completion behaviors and modes. But for users they think they are all the same, so that's why they want to see fuzzy results in some default completions as well.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2164564697@github.com>

glepnir

unread,
Jun 13, 2024, 8:25:01 AM (13 days ago) Jun 13
to vim/vim, Push

@glepnir pushed 1 commit.

  • 25b5353 fix(completion): when only fuzzy no completion insert


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/3f53ee8a7cc5ec7e5871954dc4806b6892e6c08d/after/25b5353a3e76674dd3162c5d811c0df1e1ace5c2@github.com>

glepnir

unread,
Jun 13, 2024, 8:25:25 AM (13 days ago) Jun 13
to vim/vim, Push

@glepnir pushed 1 commit.

  • e8d0ae9 fix(completion): when only fuzzy no completion insert

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/25b5353a3e76674dd3162c5d811c0df1e1ace5c2/after/e8d0ae98f04dd5cd12d1662b90e6537d7df6fe0b@github.com>

glepnir

unread,
Jun 13, 2024, 8:45:01 AM (13 days ago) Jun 13
to vim/vim, Subscribed

I tried to make fuzzy support for original pattern at the end. It works fine. But I don't use some default completions very often. So not sure if it's broken or some patterns don't work. Might need some testing and feedback. Thanks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2165551613@github.com>

zeertzjq

unread,
Jun 13, 2024, 9:03:04 AM (13 days ago) Jun 13
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2566,6 +2566,15 @@ func Test_complete_fuzzy_match()
   call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx')
   call assert_equal('fooBaz', g:word)
 
+  set completeopt=fuzzy

The 'completeopt' here includes fuzzy but not menu. Is this intended?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2115733884@github.com>

glepnir

unread,
Jun 13, 2024, 9:05:27 AM (13 days ago) Jun 13
to vim/vim, Subscribed

@glepnir commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2566,6 +2566,15 @@ func Test_complete_fuzzy_match()
   call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx')
   call assert_equal('fooBaz', g:word)
 
+  set completeopt=fuzzy

yup .when no menu it will complete the word directly before .so i just set it to fuzzy to check this behavior..


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2115739517@github.com>

glepnir

unread,
Jun 13, 2024, 9:38:51 AM (13 days ago) Jun 13
to vim/vim, Push

@glepnir pushed 1 commit.

  • d0806b2 fix(completion): when only fuzzy no completion insert

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/e8d0ae98f04dd5cd12d1662b90e6537d7df6fe0b/after/d0806b2384d47d46c86334ae752edeb992606e2f@github.com>

Christian Brabandt

unread,
Jun 13, 2024, 11:05:02 AM (13 days ago) Jun 13
to vim/vim, Subscribed

alright, convinced :)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2165943722@github.com>

Christian Brabandt

unread,
Jun 13, 2024, 11:10:12 AM (13 days ago) Jun 13
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In src/insexpand.c:

> @@ -4606,11 +4611,38 @@ get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col)
 	    STRCPY((char *)compl_pattern, "\\<");
 	    (void)quote_meta(compl_pattern + 2, line + compl_col,
 		    compl_length);
-	}
+        }
+

hm, whitespace change?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2116079735@github.com>

zeertzjq

unread,
Jun 13, 2024, 5:58:03 PM (13 days ago) Jun 13
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/insexpand.c:

>      }
 
     compl_patternlen = STRLEN(compl_pattern);
 
+    if (compl_fuzzy_match)
+    {
+	// Adjust size to avoid buffer overflow
+	fuzzy_len = (size_t)compl_length * 4 + 5;
+	// Allocate enough space
+	fuzzy_pattern = alloc(fuzzy_len);

Need to check for NULL


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2117098144@github.com>

glepnir

unread,
Jun 14, 2024, 2:21:21 AM (12 days ago) Jun 14
to vim/vim, Push

@glepnir pushed 1 commit.

  • 563a9c9 fix(completion): when only fuzzy no completion insert

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/d0806b2384d47d46c86334ae752edeb992606e2f/after/563a9c9eb96ff993985c564165f73d7ce91f9ecf@github.com>

glepnir

unread,
Jun 14, 2024, 2:34:34 AM (12 days ago) Jun 14
to vim/vim, Push

@glepnir pushed 1 commit.

  • a60c1f2 fix(completion): when only fuzzy no completion insert

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/563a9c9eb96ff993985c564165f73d7ce91f9ecf/after/a60c1f2b53b7116bee629d9afd509b95ad5da849@github.com>

zeertzjq

unread,
Jun 14, 2024, 6:30:25 AM (12 days ago) Jun 14
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/insexpand.c:

> @@ -4606,11 +4611,42 @@ get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col)
 	    STRCPY((char *)compl_pattern, "\\<");
 	    (void)quote_meta(compl_pattern + 2, line + compl_col,
 		    compl_length);
-	}
+        }

Why is the Tab changed into spaces here?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2118060303@github.com>

glepnir

unread,
Jun 14, 2024, 7:10:21 AM (12 days ago) Jun 14
to vim/vim, Push

@glepnir pushed 1 commit.

  • d260cfe fix(completion): when only fuzzy no completion insert

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/a60c1f2b53b7116bee629d9afd509b95ad5da849/after/d260cfec5c60f80c7e89d6a752af51f9174410cc@github.com>

techntools

unread,
Jun 14, 2024, 10:30:27 AM (12 days ago) Jun 14
to vim/vim, Subscribed

@chrisbra @glepnir

Thanks for this feature.

My primary completion method is keyword completion. When I start typing I am fairly certain about first character of the word I want to be completed. I get the candidates starting with that character and fuzzy match the word I want.

Too many candidates will be generated if we generate them as well with fuzzy. Which may slow down the completion. I would suggest generate candidates with fuzzy under another option such as fuzzysearch.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2168169759@github.com>

Christian Brabandt

unread,
Jun 14, 2024, 2:11:43 PM (12 days ago) Jun 14
to vim/vim, Subscribed

so maybe we can use a separate sub-option 'fuzzysearch' for the 'completeopt' option then?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2168526983@github.com>

techntools

unread,
Jun 14, 2024, 2:38:22 PM (12 days ago) Jun 14
to vim/vim, Subscribed

Yes


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2168565133@github.com>

Shane-XB-Qian

unread,
Jun 14, 2024, 2:54:01 PM (12 days ago) Jun 14
to vim/vim, Subscribed

> @chrisbra @glepnir
>
> Thanks for this feature.
>
> My primary completion method is keyword completion. When I start typing I am fairly certain about first character of the word I want to be completed. I get the candidates starting with that character and fuzzy match the word I want.
>
> Too many candidates will be generated if we generate them as well with fuzzy. Which may slow down the completion. I would suggest generate candidates with fuzzy under another option such as ```fuzzysearch```.

maybe just let the 'fuzzy' do the filter, but not the generate, as your (chris) initially said somewhere, where/when after the base inserted, i guess so.

--
shane.xb.qian


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2168584379@github.com>

techntools

unread,
Jun 14, 2024, 3:02:48 PM (12 days ago) Jun 14
to vim/vim, Subscribed

Let the people have it if they want it


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2168596434@github.com>

Shane-XB-Qian

unread,
Jun 14, 2024, 3:18:48 PM (12 days ago) Jun 14
to vim/vim, Subscribed

> Let the people have it if they want it

ok, if author felt impl it was easy and/or simple, or you would impl it.
// and if was less impact current usage.
// btw: lsp server may offer fuzzy compl items generation already, and knew it would be slow if fuzzy to e.g keyword compl in practise.
// and check my `https://github.com/Shane-XB-Qian/jj` there is a fuzzy filter for a simple and funny fs filter and jump, but only filter.

--
shane.xb.qian


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2168617802@github.com>

glepnir

unread,
Jun 14, 2024, 9:34:36 PM (12 days ago) Jun 14
to vim/vim, Subscribed

Ping me when there is a result and I will implement it


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2169027625@github.com>

Christian Brabandt

unread,
Jun 15, 2024, 9:40:57 AM (11 days ago) Jun 15
to vim/vim, Subscribed

yeah, let's have another option value for 'completeopt' that determines how the candidates for the completion-menu are collected. It may be called 'fuzzysearch' or 'fuzzycollect' then (not good on names), but it seems good to give people the chance on how they want the completion to work. Thanks!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2169654128@github.com>

techntools

unread,
Jun 15, 2024, 10:24:46 AM (11 days ago) Jun 15
to vim/vim, Subscribed

Thanks.

I vote for fuzzycollect.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2169766833@github.com>

Shane-XB-Qian

unread,
Jun 15, 2024, 3:13:11 PM (11 days ago) Jun 15
to vim/vim, Subscribed

yeah, let's have another option value for 'completeopt' that determines how the candidates for the completion-menu are collected. It may be called 'fuzzysearch' or 'fuzzycollect' then (not good on names), but it seems good to give people the chance on how they want the completion to work. Thanks!

ok, so 'fuzzy' of completeopt do only filter, right? seems ok, if so.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2170538976@github.com>

glepnir

unread,
Jun 16, 2024, 3:57:33 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • 5829643 feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/d260cfec5c60f80c7e89d6a752af51f9174410cc/after/5829643433ebdb0c177ee2d4e2f4aa8d1734bc9a@github.com>

glepnir

unread,
Jun 16, 2024, 3:58:14 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • c84745b feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/5829643433ebdb0c177ee2d4e2f4aa8d1734bc9a/after/c84745ba7c6a8fd784f9d9a70957a4624f0c2a74@github.com>

glepnir

unread,
Jun 16, 2024, 4:13:09 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • 44e096b feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/c84745ba7c6a8fd784f9d9a70957a4624f0c2a74/after/44e096b7cef434e8c0d17ba8badbd5b3e9f37489@github.com>

glepnir

unread,
Jun 16, 2024, 4:27:33 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • b99cea9 feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/44e096b7cef434e8c0d17ba8badbd5b3e9f37489/after/b99cea92e7f82d6049dfa0490987a37d301b0900@github.com>

glepnir

unread,
Jun 16, 2024, 4:28:21 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • bb464dc feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/b99cea92e7f82d6049dfa0490987a37d301b0900/after/bb464dccc85fdc3efdabb99f4cf91fa3e9f60023@github.com>

glepnir

unread,
Jun 16, 2024, 4:37:16 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • 1f6c7e9 feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/bb464dccc85fdc3efdabb99f4cf91fa3e9f60023/after/1f6c7e9d129a0c2215cc19be0a0b83c05bdd4682@github.com>

glepnir

unread,
Jun 16, 2024, 4:48:38 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • f121421 feat(completion): add fuzzycollect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/1f6c7e9d129a0c2215cc19be0a0b83c05bdd4682/after/f121421d6a41bf4b4392e74b7526b60d4bdadb90@github.com>

zeertzjq

unread,
Jun 16, 2024, 4:50:48 AM (10 days ago) Jun 16
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2599,7 +2630,7 @@ func Test_complete_fuzzy_match()
   unlet g:word
 endfunc
 
-" Check that tie breaking is stable for completeopt+=fuzzy (which should
+" Check that tie breaking is stable for completeopt+=fuzzycollect (which should

?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2121258572@github.com>

glepnir

unread,
Jun 16, 2024, 4:51:42 AM (10 days ago) Jun 16
to vim/vim, Subscribed

@glepnir commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2599,7 +2630,7 @@ func Test_complete_fuzzy_match()
   unlet g:word
 endfunc
 
-" Check that tie breaking is stable for completeopt+=fuzzy (which should
+" Check that tie breaking is stable for completeopt+=fuzzycollect (which should

emm this test can be safe remove right ? sry for typo


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2121258797@github.com>

zeertzjq

unread,
Jun 16, 2024, 4:52:35 AM (10 days ago) Jun 16
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2599,7 +2630,7 @@ func Test_complete_fuzzy_match()
   unlet g:word
 endfunc
 
-" Check that tie breaking is stable for completeopt+=fuzzy (which should
+" Check that tie breaking is stable for completeopt+=fuzzycollect (which should

Why remove?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2121258928@github.com>

glepnir

unread,
Jun 16, 2024, 4:52:37 AM (10 days ago) Jun 16
to vim/vim, Push

@glepnir pushed 1 commit.

  • 1f0c574 feat(completion): add fuzzycollect


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/before/f121421d6a41bf4b4392e74b7526b60d4bdadb90/after/1f0c5745bbfde9218262dbd39f3bdafdf56f1dee@github.com>

glepnir

unread,
Jun 16, 2024, 4:54:28 AM (10 days ago) Jun 16
to vim/vim, Subscribed

@glepnir commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2599,7 +2630,7 @@ func Test_complete_fuzzy_match()
   unlet g:word
 endfunc
 
-" Check that tie breaking is stable for completeopt+=fuzzy (which should
+" Check that tie breaking is stable for completeopt+=fuzzycollect (which should

fuzzy not work for this keyword compleiton mode. It seems a bit redundant. but there is no harm in keeping it


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2121259772@github.com>

Shane-XB-Qian

unread,
Jun 16, 2024, 5:12:31 AM (10 days ago) Jun 16
to vim/vim, Subscribed

@Shane-XB-Qian commented on this pull request.


In src/testdir/test_ins_complete.vim:

> @@ -2599,7 +2630,7 @@ func Test_complete_fuzzy_match()
   unlet g:word
 endfunc
 
-" Check that tie breaking is stable for completeopt+=fuzzy (which should
+" Check that tie breaking is stable for completeopt+=fuzzycollect (which should

um.. you may mis-understand, fuzzy of completeopt is to support for (filter) all kinds compl included keyword, vs/but to e.g keyword compl mode maybe not recommend using fuzzycollect.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2121264160@github.com>

Shane-XB-Qian

unread,
Jun 16, 2024, 5:17:37 AM (10 days ago) Jun 16
to vim/vim, Subscribed

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/review/2121265149@github.com>

Christian Brabandt

unread,
Jun 17, 2024, 12:40:24 PM (9 days ago) Jun 17
to vim/vim, Subscribed

so this is ready?


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2173865783@github.com>

glepnir

unread,
Jun 18, 2024, 2:16:45 AM (8 days ago) Jun 18
to vim/vim, Subscribed

Any other questions about the code? @zeertzjq I'm not sure if this is a result of discussion, fuzzycollect is used for some completion modes that use regular expressions to get matching results right ? feel like the fuzzyclloect is a bit long :) if LGTY then is ready.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2175126169@github.com>

Christian Brabandt

unread,
Jun 19, 2024, 2:14:10 PM (7 days ago) Jun 19
to vim/vim, Subscribed

No complaints? I take that as a general agreement :) Thanks everybody!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/c2179268347@github.com>

Christian Brabandt

unread,
Jun 19, 2024, 2:26:30 PM (7 days ago) Jun 19
to vim/vim, Subscribed

Closed #14976 via 43eef88.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14976/issue_event/13219795785@github.com>

Reply all
Reply to author
Forward
0 new messages