[vim/vim] Fix: Backspace does not clear selected item in insert-completion (PR #18265)

68 views
Skip to first unread message

girish

unread,
Sep 10, 2025, 9:12:21 AM (8 days ago) Sep 10
to vim/vim, Subscribed

Fix: Backspace does not clear selected item in insert-completion

Problem:
After selecting and inserting a completion item, pressing <BS> to delete part of the inserted text does not clear the selection.

  • The completion item stays selected even though the text no longer matches.
  • Pressing <C-N> moves to the next item instead of restarting from the first.
  • If only one item is available, <C-N> does nothing (buggy).
  • This differs from the behavior of other editors/IDEs.
Screenshot.2025-09-10.at.8.40.11.AM.png (view on web)

Expected behavior:
Once the inserted text no longer matches the selected item, it should be deselected.

Notes:
This bug is also present in v9010754, so it may have been longstanding.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/18265

Commit Summary

  • 1c25103 Fix: Backspace does not clear selected item in insert-completion

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265@github.com>

zeertzjq

unread,
Sep 10, 2025, 9:22:10 AM (8 days ago) Sep 10
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

The completion item stays selected even though the text no longer matches.

How does the text no longer match? Even in your screnshot the text still matches.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3274961960@github.com>

zeertzjq

unread,
Sep 10, 2025, 9:27:23 AM (8 days ago) Sep 10
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

I don't think this is an improvement.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3274981477@github.com>

Christian Brabandt

unread,
Sep 10, 2025, 12:37:00 PM (7 days ago) Sep 10
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18265)

There seems to be some inconsistency here. When pressing <bs> after one has selected some item from the pum and the list of matches is updated and includes more alternatives, the selected item vanishes. But if one presses <bs> and the list of matches does not change, then the selected item stays the same.
I don't have a preference either way, as long as we behave what is documented at popupmenu-keys (but it doesn't mention what should happen with the selected item). Actually there seem to be 3 different behaviours according to my short test.

E.g. what I mean is the difference in the this. With the following lines in a buffer (using vim --clean)

foobarfoo
foobar
foobarbaz
foobarbay
foobarb

pressing GA<C-N><Down><BS> -> keeps the selected item foobarbay
pressing GA<C-N><Down><BS><BS> -> selects a new item foobarbaz
pressing GA<C-N><Down><BS><BS><BS> -> updates the list of matches, removes the selection completly.

As far as I can see this behaves already like this on v9.0.0000.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3275700022@github.com>

girish

unread,
Sep 10, 2025, 12:43:49 PM (7 days ago) Sep 10
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

Example 1: Vim (--clean)

  1. Start Vim:

    vim --clean -c 'set cot=menuone'
  2. Type foobar.

  3. On the next line, type f<C-N> to open the completion menu.

  4. Press <BS> twice to delete characters.

At this point, the menu shows the item selected but not matching the leader:

Screenshot.2025-09-10.at.6.22.48.PM.png (view on web)

Now press <C-N>. Nothing happens because the previously selected item was deselected. The user just wasted a keystroke — a clear UX flaw.

Screenshot.2025-09-10.at.6.23.05.PM.png (view on web)

Example 2: Neovim + nvim-cmp

The exact same scenario (as the original example) behaves correctly: the menu updates intuitively, item gets deselected after <BS>, and <C-N> works as expected.

Screenshot.2025-09-10.at.6.21.03.PM.png (view on web)

Takeaway: The PR fixes a subtle but important UX issue, preventing wasted keystrokes and making completion behavior more predictable.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3275718632@github.com>

zeertzjq

unread,
Sep 10, 2025, 8:22:07 PM (7 days ago) Sep 10
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

Nothing happens because the previously selected item was deselected.

Hmm, I won't call this "nothing happens", as that'll mean the selected item doesn't change either.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3276954614@github.com>

girish

unread,
Sep 11, 2025, 3:14:50 AM (7 days ago) Sep 11
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

Nothing happens because the previously selected item was deselected.

Hmm, I won't call this "nothing happens", as that'll mean the selected item doesn't change either.

From the user’s perspective, nothing happens. What matters is the behavior at the cursor, not the color of an item in a popup menu. This point isn’t up for debate.

Meanwhile, I don't see why one will have a reason to navigate the popup menu after deleting some characters if the menu items haven't changed.

You’re shifting the topic. Let’s stay focused—I don’t have time to go down unrelated paths.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3278736351@github.com>

zeertzjq

unread,
Sep 11, 2025, 3:19:12 AM (7 days ago) Sep 11
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

You’re shifting the topic. Let’s stay focused—I don’t have time to go down unrelated paths.

If we don't know the circumstances where this happens, how can we decide the desired behavior?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3278776035@github.com>

girish

unread,
Sep 11, 2025, 3:48:59 AM (7 days ago) Sep 11
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

You’re shifting the topic. Let’s stay focused—I don’t have time to go down unrelated paths.

If we don't know the circumstances where one wants to do this, how can we decide the desired behavior?

Who exactly is “we”?

The correct behavior has already been established. Please review my earlier comments, including the Neovim example.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3278965401@github.com>

zeertzjq

unread,
Sep 11, 2025, 4:11:17 AM (7 days ago) Sep 11
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

Who exactly is “we”?

Anyone who wants to decide what the correct behavior is.

The correct behavior has already been established. Please review my earlier comments, including the Neovim example.

I have read them and I don't think the correct behavior has been established. I have a different example:

  1. :set completeopt=menuone,noselect
  2. Trigger completion like your original example, but select a matching using <Down> key instead of <C-N>, which doesn't insert the selected match
  3. Typing <C-L> adds a character from the current match, while typing <BS> removes a character from the current match

Before this PR, the current match doesn't change in step 3, while after this PR the current match changes when typing <BS>.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3279077663@github.com>

gcanat

unread,
Sep 11, 2025, 4:57:20 AM (7 days ago) Sep 11
to vim/vim, Subscribed

@gcanat commented on this pull request.


In src/insexpand.c:

> @@ -2602,6 +2606,11 @@ ins_compl_addleader(int c)
 	    return;
 	}
 
+	// "preinsert" insertes the first match via compl_shown_match

small typo

⬇️ Suggested change
-	// "preinsert" insertes the first match via compl_shown_match
+	// "preinsert" inserts the first match via compl_shown_match


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/review/3209993550@github.com>

girish

unread,
Sep 11, 2025, 5:00:28 AM (7 days ago) Sep 11
to vim/vim, Push

@girishji pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/before/1c251030d3ac66cee9e905d407ac37874d597a2c/after/c1b72cc58b8c2e68a8d93b714afbe2ca32709192@github.com>

girish

unread,
Sep 11, 2025, 5:06:13 AM (7 days ago) Sep 11
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

Who exactly is “we”?

Anyone who wants to decide what the correct behavior is.

I referred to the first use of "we", not the last.

The correct behavior has already been established. Please review my earlier comments, including the Neovim example.

I have read them and I don't think the correct behavior has been established. I have a different example:

  1. :set completeopt=menuone,noselect
  2. Trigger completion like your original example, but select a matching using <Down> key instead of <C-N>, which doesn't insert the selected match
  3. Typing <C-L> adds a character from the current match, while typing <BS> removes a character from the current match

Before this PR, the current match doesn't change in step 3, while after this PR the current match changes when typing <BS>. On the other hand, there are more cases where the selected item doesn't match the inserted text that clearly aren't bugs.

This behavior is still correct in this PR, since the previous behavior revealed a UX flaw when dealing with a single item, as I mentioned above.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3279343124@github.com>

zeertzjq

unread,
Sep 11, 2025, 5:27:20 AM (7 days ago) Sep 11
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

I referred to the first use of "we", not the last.

These two are the same.

This behavior is still correct in this PR

No it isn't.
Before:
https://github.com/user-attachments/assets/0e48ea29-d1c4-437f-8ccd-dedecaaa28d5
After:
https://github.com/user-attachments/assets/bec2fe4d-be06-45a0-94b6-4dbfc6559f0f


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3279468972@github.com>

girish

unread,
Sep 11, 2025, 6:54:13 AM (7 days ago) Sep 11
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

The behavior implemented in this PR is correct, as it prevents a UX flaw. Neovim’s behavior is also correct, and the same reasoning applies to the Up/Down keys.

Consider a real-world example: when many matches are present and the scroll bar is active, user might select a match further down the list, causing the beginning of the menu to scroll out of view. If the user then deletes several characters (realizing that wasn’t the right match), the beginning of the list—where the most relevant results usually are—is no longer visible. At this point, pressing <C-n> won’t return to the top of the list; instead, it will select the next item relative to the previously chosen match, which is less relevant than the results at the beginning.

Screenshot.2025-09-11.at.12.35.49.PM.png (view on web)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3279906467@github.com>

zeertzjq

unread,
Sep 11, 2025, 7:12:44 AM (7 days ago) Sep 11
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

If the user then deletes several characters (realizing that wasn’t the right match), the beginning of the list—where the most relevant results usually are—is no longer visible.

  1. If deleting characters does not add more matches, why will the user delete several characters after they realize they selected the wrong match, when they can just select another match directly?
  2. If deleting characters does add more matches, I'd say it's more likely that the user mistook a match for a similar one (e.g. mistaking foo47 for foo48 in your screenshot), and similar matches are more likely to be grouped together.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3280000697@github.com>

girish

unread,
Sep 11, 2025, 7:49:27 AM (7 days ago) Sep 11
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

The example I described above is a real-world case I’ve personally run into several times, which is why I made this change. Now you’re trying to decide for the user how they should behave!

  1. If deleting characters does not add more matches, why will the user delete several characters after they realize they selected the wrong match, when they can just select another match directly?

Because I may not know the exact match I want yet—I just know the prefix I’d like to use as the starting point. Once I change that prefix, I expect the most relevant results for it.

  1. If deleting characters does add more matches

It doesn’t always, as the example illustrates.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3280176145@github.com>

zeertzjq

unread,
Sep 11, 2025, 8:14:33 AM (7 days ago) Sep 11
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

The example I described above is a real-world case I’ve personally run into several times, which is why I made this change. Now you’re trying to decide for the user how they should behave!

No I'm not, because this is already the current behavior.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3280298042@github.com>

girish

unread,
Sep 11, 2025, 10:34:55 AM (7 days ago) Sep 11
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

I’d like to wrap up this discussion with a quick summary:

  • This PR fixes two issues:
    1. UX flaw ref
    2. Localizing (sticking) to irrelevant context ref.
  • The behavior is consistent with Neovim ref.

With that in mind, I believe this PR should be merged.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3281107994@github.com>

zeertzjq

unread,
Sep 11, 2025, 10:39:10 AM (7 days ago) Sep 11
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18265)

It's possible that what's actually missing here is a way to quickly jump to the start of the the popup menu. With that it's easy to achieve to behavior introduced in this by with a mapping. On the other hand with this PR the old behavior is hard to achieve.

The behavior is consistent with Neovim

nvim-cmp is not Neovim.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3281132868@github.com>

Shane-XB-Qian

unread,
Sep 12, 2025, 2:28:51 AM (6 days ago) Sep 12
to vim/vim, Subscribed
Shane-XB-Qian left a comment (vim/vim#18265)
not sure what's you are arguing detail here,
but the case to my side was selected item (after `<bs>`) sometimes was invisible,

this PR seems make it just de-selected? but what if user did not set `noselect` to `cot`?
looks this made it always *no* pre-selected when `<bs>`?

tho sometimes such case happened even no this PR, after `<bs>`, became no pre-selected somehow;
but compared to `sometimes` i preferred *not* `always`,

*or* would you make it pre-selected one and visible, when no `noselect` in `cot`?

--
shane.xb.qian


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3283885147@github.com>

girish

unread,
Sep 13, 2025, 2:02:29 AM (5 days ago) Sep 13
to vim/vim, Push

@girishji pushed 2 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/before/c1b72cc58b8c2e68a8d93b714afbe2ca32709192/after/116267d9b11b12c640f3942c4f3c39fcc488ffd5@github.com>

girish

unread,
Sep 13, 2025, 2:08:10 AM (5 days ago) Sep 13
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

It's possible that what's actually missing here is a way to quickly jump to the start of the the popup menu. With that it'll be easy to achieve to behavior introduced in this by with a mapping. On the other hand with this PR the old behavior is hard to achieve.

The behavior is consistent with Neovim

No it isn't. It's consistent with nvim-cmp, which IIRC reimplements the entire popup menu from scratch.

I suppose it is possible to provide a mechanism to deselect the item after <BS>. But I've constrained this change to autocompletion. It is simpler this way.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3287642370@github.com>

girish

unread,
Sep 13, 2025, 2:08:51 AM (5 days ago) Sep 13
to vim/vim, Push

@girishji pushed 1 commit.

  • d348e82 Merge branch 'vim:master' into badselect

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/before/116267d9b11b12c640f3942c4f3c39fcc488ffd5/after/d348e829075ff78c291ac0b3008a6762e75667a9@github.com>

girish

unread,
Sep 13, 2025, 5:35:27 AM (5 days ago) Sep 13
to vim/vim, Push

@girishji pushed 2 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/before/d348e829075ff78c291ac0b3008a6762e75667a9/after/05f5d81eae661ca329408f2afc1e6c4bfefe14b8@github.com>

Christian Brabandt

unread,
Sep 14, 2025, 2:30:18 PM (3 days ago) Sep 14
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18265)

I cannot seem to reproduce the problem here. It seems to work exactly the same with or without the patch. Same with this. I tried a few variations of hitting <c-n> going down until item 41 than backspacing a few characters. The selected item stays it is not removed and hitting <c-n> again does not start from the top again.
this also did not change.

So what am I doing wrong?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3289759438@github.com>

girish

unread,
Sep 15, 2025, 5:46:41 AM (3 days ago) Sep 15
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

I cannot seem to reproduce the problem here. It seems to work exactly the same with or without the patch. Same with this. I tried a few variations of hitting <c-n> going down until item 41 than backspacing a few characters. The selected item stays it is not removed and hitting <c-n> again does not start from the top again. this also did not change.

So what am I doing wrong?

Are you using :set autocomplete? In the last commit, I limited this change to affect only autocompletion.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3291305071@github.com>

Christian Brabandt

unread,
Sep 15, 2025, 2:54:26 PM (2 days ago) Sep 15
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18265)

I see now, thanks.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3293499171@github.com>

Christian Brabandt

unread,
Sep 15, 2025, 4:42:34 PM (2 days ago) Sep 15
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18265)

Hm, forgot to close. Fixed as of: 5c9b71d


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3293886077@github.com>

Christian Brabandt

unread,
Sep 15, 2025, 4:42:35 PM (2 days ago) Sep 15
to vim/vim, Subscribed

Closed #18265.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/issue_event/19710518661@github.com>

girish

unread,
Sep 16, 2025, 1:38:36 AM (yesterday) Sep 16
to vim/vim, Subscribed
girishji left a comment (vim/vim#18265)

Thanks.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18265/c3295504137@github.com>

Reply all
Reply to author
Forward
0 new messages