From 8ba79b460129d188dd669a8a816927e9d4c1dbe5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 15 Apr 2026 07:03:34 +0800 Subject: [PATCH] vim-patch:9.2.0345: Wrong autoformatting with 'autocomplete' (#39060) Problem: Wrong autoformatting with 'autocomplete'. Solution: Don't trigger autoformatting when ending autocompletion without selecting an item (zeertzjq). fixes: vim/vim#19954 closes: vim/vim#19970 https://github.com/vim/vim/commit/efbd482116d0f1a244b436a46ce3544b016de04b (cherry picked from commit 65680f59d153c3ec08297d3a9fe7bc72ebf48464) --- src/nvim/insexpand.c | 2 +- test/old/testdir/test_ins_complete.vim | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 2de4be9822..dfaedea41d 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2614,7 +2614,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) do_c_expr_indent(); want_cindent = false; // don't do it again } - } else { + } else if (!compl_autocomplete || compl_used_match) { const int prev_col = curwin->w_cursor.col; // put the cursor on the last char, for 'tw' formatting diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index 5d480333e7..4a48148227 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -6402,4 +6402,20 @@ func Test_ins_register_preinsert_autocomplete() delfunc TestOmni endfunc +func Test_autocomplete_with_auto_format() + call Ntest_override("char_avail", 1) + new + setlocal formatoptions=tcq textwidth=9 autocomplete noautoindent + call feedkeys("ia b c d\ie f g\", 'tx') + call assert_equal(['a b c e f', 'gd'], getline(1, '$')) + + %delete + setlocal autoindent + call feedkeys("ia b c d\ie f g\", 'tx') + call assert_equal(['a b c e f', 'gd'], getline(1, '$')) + + bw! + call Ntest_override("char_avail", 0) +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable