diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index f6725ac85b..2d4d05903e 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -1134,7 +1134,7 @@ autocompletion. To use |i_CTRL-N| or |i_CTRL-X_CTRL-N| specifically, press |CTRL-E| first to dismiss the popup menu (see |complete_CTRL-E|). *ins-autocompletion-example* -Example setup~ +Example setup ~ A typical configuration for automatic completion with a popup menu: > set autocomplete set complete=.^5,w^5,b^5,u^5 diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 7c718732f2..988113b819 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1675,15 +1675,15 @@ A jump table for the options with a short description can be found at |Q_op|. with "menu" or "menuone". Overrides "preview". preinsert - When autocompletion is not enabled, inserts the part of the + When 'autocomplete' is not active, inserts the part of the first candidate word beyond the current completion leader, - highlighted with |hl-ComplMatchIns|. The cursor does not - move. Requires "fuzzy" unset and "menuone" in 'completeopt'. + highlighted with |hl-PreInsert|. The cursor doesn't move. + Requires "fuzzy" unset and "menuone" in 'completeopt'. - When 'autocomplete' is enabled, inserts the longest common - prefix of matches (from all shown items or buffer-specific - matches), highlighted with |hl-PreInsert|. This occurs only - when no menu item is selected. Press CTRL-Y to accept. + When 'autocomplete' is active, inserts the longest common + prefix of matches (from all shown items or from the + current buffer items). This occurs only when no menu item + is selected. Press CTRL-Y to accept. preview Show extra information about the currently selected completion in the preview window. Only works in diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 8b2a4d10b1..0037546540 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -5354,7 +5354,7 @@ PmenuMatchSel Popup menu: Matched text in selected item. Combined with *hl-ComplMatchIns* ComplMatchIns Matched text of the currently inserted completion. *hl-PreInsert* -PreInsert Text inserted during autocompletion when "preinsert". +PreInsert Text inserted when "preinsert" is in 'completeopt'. *hl-ComplHint* ComplHint Virtual text of the currently selected completion. *hl-ComplHintMore* diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua index a545b75c26..2b051e4223 100644 --- a/runtime/lua/vim/_meta/options.lua +++ b/runtime/lua/vim/_meta/options.lua @@ -1218,15 +1218,15 @@ vim.go.cia = vim.go.completeitemalign --- with "menu" or "menuone". Overrides "preview". --- --- preinsert ---- When autocompletion is not enabled, inserts the part of the +--- When 'autocomplete' is not active, inserts the part of the --- first candidate word beyond the current completion leader, ---- highlighted with `hl-ComplMatchIns`. The cursor does not ---- move. Requires "fuzzy" unset and "menuone" in 'completeopt'. +--- highlighted with `hl-PreInsert`. The cursor doesn't move. +--- Requires "fuzzy" unset and "menuone" in 'completeopt'. --- ---- When 'autocomplete' is enabled, inserts the longest common ---- prefix of matches (from all shown items or buffer-specific ---- matches), highlighted with `hl-PreInsert`. This occurs only ---- when no menu item is selected. Press CTRL-Y to accept. +--- When 'autocomplete' is active, inserts the longest common +--- prefix of matches (from all shown items or from the +--- current buffer items). This occurs only when no menu item +--- is selected. Press CTRL-Y to accept. --- --- preview Show extra information about the currently selected --- completion in the preview window. Only works in diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 075e4ba86b..d4269bae5f 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1095,10 +1095,14 @@ static void ins_compl_insert_bytes(char *p, int len) /// -1 means normal item. int ins_compl_col_range_attr(linenr_T lnum, int col) { + const bool has_preinsert = ins_compl_has_preinsert(); + int attr; if ((get_cot_flags() & kOptCotFlagFuzzy) - || (!compl_autocomplete + || (!has_preinsert && (attr = syn_name2attr("ComplMatchIns")) == 0) + || (!compl_autocomplete && has_preinsert + && (attr = syn_name2attr("PreInsert")) == 0) || (compl_autocomplete && (!compl_autocomplete_preinsert || (attr = syn_name2attr("PreInsert")) == 0))) { @@ -2283,9 +2287,7 @@ static void ins_compl_new_leader(void) compl_enter_selects = false; } else if (ins_compl_has_preinsert() && compl_leader.size > 0) { if (compl_started && compl_autocomplete && !ins_compl_preinsert_effect()) { - if (ins_compl_insert(true, true) != OK) { - (void)ins_compl_insert(false, false); - } else { + if (ins_compl_insert(true, true) == OK) { compl_autocomplete_preinsert = true; } } else { diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 9c75205699..00392dcfc1 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1,4 +1,4 @@ --- vim: tw=80 +-- vim: tw=78 --- @class vim.option_meta --- @field full_name string @@ -1700,15 +1700,15 @@ local options = { with "menu" or "menuone". Overrides "preview". preinsert - When autocompletion is not enabled, inserts the part of the + When 'autocomplete' is not active, inserts the part of the first candidate word beyond the current completion leader, - highlighted with |hl-ComplMatchIns|. The cursor does not - move. Requires "fuzzy" unset and "menuone" in 'completeopt'. + highlighted with |hl-PreInsert|. The cursor doesn't move. + Requires "fuzzy" unset and "menuone" in 'completeopt'. - When 'autocomplete' is enabled, inserts the longest common - prefix of matches (from all shown items or buffer-specific - matches), highlighted with |hl-PreInsert|. This occurs only - when no menu item is selected. Press CTRL-Y to accept. + When 'autocomplete' is active, inserts the longest common + prefix of matches (from all shown items or from the + current buffer items). This occurs only when no menu item + is selected. Press CTRL-Y to accept. preview Show extra information about the currently selected completion in the preview window. Only works in diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 1064f74a9f..4c11c1a661 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -26,6 +26,7 @@ describe('completion', function() screen:add_extra_attr_ids { [100] = { foreground = Screen.colors.Gray0, background = Screen.colors.Yellow }, [101] = { background = Screen.colors.Gray0 }, + [102] = { foreground = Screen.colors.SeaGreen }, } end) @@ -1501,7 +1502,7 @@ describe('completion', function() foo | foobar | foobarbaz | - f^oo | + f{102:^oo} | {12:foo }{1: }| {4:foobar }{1: }| {4:foobarbaz }{1: }| diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index 2fca84e227..104acfa7bc 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -5755,6 +5755,12 @@ func Test_autocomplete_completeopt_preinsert() call feedkeys($"cwch\\n.n.", 'tx') call assert_equal(repeat(['changed'], 3), getline(1, 3)) + " Select a match and delete up to text equal to another match + %delete + call setline(1, ["foobar", "foo"]) + call feedkeys("Go\", 'tx') + call DoTest("f\\\\\\", 'foo', 3) + %delete _ let &l:undolevels = &l:undolevels normal! ifoo