Skip to content

Entry in wildmenu is mutated when searching #17654

Description

@techntools

Steps to reproduce

@girishji Thank you for improving the Vim search

I tried code suggested in #17570. Compiled latest Vim.

I have ignorecase and smartcase on

Screencast.from.2025-07-03.18-29-49.webm

Expected behaviour

I am expecting w0rld stays the same in menu. But its changing in the menu itself.

Version of Vim

Latest

Environment

Ubuntu 24

tmux in Kitty

Using bash

Logs and stack traces

Activity

  1. girishji commented on Jul 3, 2025

    @girishji
    Contributor

    This is working as intended. Note that hlsearch highlights correctly even when the case differs—for example, the o in wOrld. If you select world from the menu and press Enter, the cursor will jump to the wOrld match, as expected.

    Importantly, the portion of the search pattern already typed by the user is not modified when a completion item is inserted. This preserves special regex elements such as wildcards, grouping brackets, and word-boundary tags (\<, \>, ^, etc.), which is especially critical for predictable outcomes in commands like :s.

    The original design of the PR used a different approach: it expanded the pattern and displayed a literal fragment from the buffer (e.g., wO[rld] instead of wo[rld]). While this may seem intuitive, it breaks in cases where regex anchors are used. For example, with a pattern like \<wo, if both world and woworld exist in the buffer, expanding the pattern would remove the \< anchor and lead to incorrect matches. One of the menu items might be world without the anchor, which would match [wo]world—not the intended behavior. The PR also attempted to re-insert \<s after pattern expansion, but doing so robustly proved difficult, since these anchors can appear anywhere.

    The current implementation takes a more reliable approach: it preserves the exact pattern typed by the user and appends only the suggested completion. Internally, it still expands the full pattern (including \ns) to verify ignorecase and smartcase, but the menu displays only the completion portion appended to the original input. This ensures both accuracy and predictable behavior.

  2. techntools commented on Jul 3, 2025

    @techntools
    Author

    @girishji

    I got the gist of it

    But still changing entries in completion menu itself seems not ok. In my example, there is only wOrld in the buffer text. No world. So I would expect to see only that in the menu.

  3. girishji commented on Jul 3, 2025

    @girishji
    Contributor

    @girishji

    I got the gist of it

    But still changing entries in completion menu itself seems not ok. In my example, there is only wOrld in the buffer text. No world. So I would expect to see only that in the menu.

    Regex-based completion cannot behave the same way as Insert-mode completion, where users typically type simple words and the menu shows matching words from the buffer. In regex contexts, users may enter arbitrarily complex patterns. Modifying the user-typed pattern when inserting a completion item can lead to incorrect or unintended matches, as explained earlier. Preserving the original pattern is crucial.

  4. techntools commented on Jul 3, 2025

    @techntools
    Author

    @girishji

    Got it

    Again thanks for the contribution

  5. girishji commented on Jul 3, 2025

    @girishji
    Contributor

    I understand your dilemma, but this is the best I could come up with!

  6. added a commit that references this issue on Jul 8, 2025
    93c2d5b
  7. added 2 commits that reference this issue on Jul 8, 2025
    5a56256
    ef0ec7e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions