patch 9.1.1859: completion: whitespace not cleared with 'ai'
Commit:
https://github.com/vim/vim/commit/6180d65751d8cc85460eb1729dd04815b9f14aa4
Author: Maxim Kim <
hab...@gmail.com>
Date: Thu Oct 16 18:32:21 2025 +0000
patch 9.1.1859: completion: whitespace not cleared with 'ai'
Problem: completion: whitespace not cleared with 'ai'
Solution: Remove spaces added by 'autoindent' when autocomplete is set
and restore did_ai in ins_compl_start() (Maxim Kim)
fixes #18560
closes: #18582
Signed-off-by: Maxim Kim <
hab...@gmail.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/src/insexpand.c b/src/insexpand.c
index 214395f55..4edcfe53e 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -7115,7 +7115,10 @@ ins_compl_start(void)
can_si = FALSE;
can_si_back = FALSE;
if (stop_arrow() == FAIL)
+ {
+ did_ai = save_did_ai;
return FAIL;
+ }
line = ml_get(curwin->w_cursor.lnum);
curs_col = curwin->w_cursor.col;
@@ -7205,6 +7208,7 @@ ins_compl_start(void)
{
VIM_CLEAR_STRING(compl_pattern);
VIM_CLEAR_STRING(compl_orig_text);
+ did_ai = save_did_ai;
return FAIL;
}
@@ -7220,6 +7224,7 @@ ins_compl_start(void)
out_flush();
}
+ did_ai = save_did_ai;
return OK;
}
diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim
index 7af4cdca6..99e49661c 100644
--- a/src/testdir/test_edit.vim
+++ b/src/testdir/test_edit.vim
@@ -458,6 +458,33 @@ func Test_autoindent_remove_indent()
call delete('Xarifile')
endfunc
+" Test for autoindent removing indent when insert mode is stopped and
+" autocomplete is enabled. Some parts of the code is exercised only when
+" interactive mode is used. So use Vim in a terminal.
+func Test_autoindent_remove_indent_with_autocomplete()
+ CheckRunVimInTerminal
+ let buf = RunVimInTerminal('-N Xarifile', {'rows': 6, 'cols' : 20})
+ call TermWait(buf)
+ call term_sendkeys(buf, ":set autoindent autocomplete
")
+ " leaving insert mode in a new line with indent added by autoindent, should
+ " remove the indent.
+ call term_sendkeys(buf, "i\<Tab>foo\<CR>\<Esc>")
+ " Need to delay for some time, otherwise the code in getchar.c will not be
+ " exercised.
+ call TermWait(buf, 50)
+ " when a line is wrapped and the cursor is at the start of the second line,
+ " leaving insert mode, should move the cursor back to the first line.
+ call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\<Esc>")
+ " Need to delay for some time, otherwise the code in getchar.c will not be
+ " exercised.
+ call TermWait(buf, 50)
+ call term_sendkeys(buf, ":w
")
+ call TermWait(buf)
+ call StopVimInTerminal(buf)
+ call assert_equal([" foo", '', repeat('x', 20)], readfile('Xarifile'))
+ call delete('Xarifile')
+endfunc
+
func Test_edit_esc_after_CR_autoindent()
new
setlocal autoindent
diff --git a/src/version.c b/src/version.c
index 3217452c8..928814250 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1859,
/**/
1858,
/**/