neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit a08aa77e4084e2b380f23b7a10f41eb20371d6c3
parent 550033d51deae35c7ba07a8201320351454bf048
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Fri, 17 Oct 2025 10:51:49 +0800

vim-patch:9.1.1859: completion: whitespace not cleared with 'ai' (#36218)

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 vim/vim#18560
closes: vim/vim#18582

https://github.com/vim/vim/commit/6180d65751d8cc85460eb1729dd04815b9f14aa4

Co-authored-by: Maxim Kim <habamax@gmail.com>
Diffstat:
Msrc/nvim/insexpand.c | 3+++
Mtest/old/testdir/test_edit.vim | 27+++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c @@ -6054,6 +6054,7 @@ static int ins_compl_start(void) can_si = false; can_si_back = false; if (stop_arrow() == FAIL) { + did_ai = save_did_ai; return FAIL; } @@ -6148,6 +6149,7 @@ static int ins_compl_start(void) API_CLEAR_STRING(compl_pattern); API_CLEAR_STRING(compl_orig_text); kv_destroy(compl_orig_extmarks); + did_ai = save_did_ai; return FAIL; } @@ -6162,6 +6164,7 @@ static int ins_compl_start(void) ui_flush(); } + did_ai = save_did_ai; return OK; } diff --git a/test/old/testdir/test_edit.vim b/test/old/testdir/test_edit.vim @@ -466,6 +466,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\n") + " 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\n") + call TermWait(buf) + call StopVimInTerminal(buf) + call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xarifile')) + call delete('Xarifile') +endfunc + func Test_edit_esc_after_CR_autoindent() new setlocal autoindent