commit f30a33858f23b6bc3c77fef44167e919c4925fdd
parent e6b2255ac784913ff7da1ea670d28d3ba850f3a8
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue, 30 Sep 2025 09:06:09 +0800
vim-patch:9.1.1800: completion: strange behaviour with 'ac' completeopt=longest,preinsert
Problem: completion: strange behaviour with 'ac'
completeopt=longest,preinsert (zeertzjq)
Solution: Let preinsert take precedence (Girish Palya)
fixes: vim/vim#18410
closes: vim/vim#18428
https://github.com/vim/vim/commit/d35e5e4237ec578962d3d577bc5a4e4f6bf4abb2
Co-authored-by: Girish Palya <girishji@gmail.com>
Diffstat:
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
@@ -2736,7 +2736,8 @@ bool ins_compl_prep(int c)
// Set "compl_get_longest" when finding the first matches.
if (ctrl_x_mode_not_defined_yet()
|| (ctrl_x_mode_normal() && !compl_started)) {
- compl_get_longest = (get_cot_flags() & kOptCotFlagLongest) != 0;
+ compl_get_longest = (get_cot_flags() & kOptCotFlagLongest) != 0
+ && !ins_compl_has_autocomplete();
compl_used_match = true;
}
diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua
@@ -1496,18 +1496,18 @@ describe('completion', function()
-- During delay wait, user can open menu using CTRL_N completion
feed('<Esc>')
- command('set completeopt=menuone,longest')
+ command('set completeopt=menuone')
feed('Sf<C-N>')
screen:expect([[
foo |
foobar |
foobarbaz |
foo^ |
- {4:foo }{1: }|
+ {12:foo }{1: }|
{4:foobar }{1: }|
{4:foobarbaz }{1: }|
{1:~ }|*2
- {5:-- Keyword completion (^N^P) }{19:Back at original} |
+ {5:-- Keyword completion (^N^P) }{6:match 1 of 3} |
]])
-- After the menu is open, ^N/^P and Up/Down should not delay
diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim
@@ -5834,7 +5834,7 @@ func Test_autocompletedelay()
call VerifyScreenDump(buf, 'Test_autocompletedelay_6', {})
" During delay wait, user can open menu using CTRL_N completion
- call term_sendkeys(buf, "\<Esc>:set completeopt=menuone,longest\<CR>")
+ call term_sendkeys(buf, "\<Esc>:set completeopt=menuone\<CR>")
call term_sendkeys(buf, "Sf\<C-N>")
call VerifyScreenDump(buf, 'Test_autocompletedelay_7', {})
@@ -5984,6 +5984,16 @@ func Test_autocomplete_longest()
call feedkeys("Go\<ESC>", 'tx')
call DoTest("f\<C-N>\<C-N>\<BS>\<BS>\<BS>\<BS>", 'foo', 3)
+ " Issue #18410: When both 'preinsert' and 'longest' are set, 'preinsert'
+ " takes precedence
+ %delete
+ set autocomplete completeopt+=longest,preinsert
+ call setline(1, ['foobar', 'foofoo', 'foobaz', ''])
+ call feedkeys("G", 'tx')
+ call DoTest("f", 'foobar', 2)
+ call assert_equal(1, g:preinserted)
+
+ " Undo
%delete _
let &l:undolevels = &l:undolevels
normal! ifoo