Skip to content

Vim f Motion Triggers Context Menu in Visual Mode #568

Closed

Description

@uNyanda
  • Date: 2026-08-09
  • Type: Bug
  • Severity: Low

Environment

  • OS: Linux
  • WM: Niri
  • Compositor: Wayland
  • Software version: 2.26.0

Description

When using Vim visual mode, the f{char} motion conflicts with the context menu shortcut.

For example, pressing fm should find and highlight the next m character. Instead, the m key triggers the context menu.

Steps to reproduce

  1. Open a note.
  2. Press v to enter visual mode.
  3. Press f.
  4. Press m.

Expected Behaviour

The pending f motion should have higher priority than the context menu shortcut.

  • Pressing fm should find and highlight the next m character.
  • Pressing m normally, without a pending f motion, should continue to trigger the context menu.

Actual Behaviour

When f is pressed in visual mode, pressing m triggers the context menu instead of being interpreted as the target character for the pending f motion.

Additional Notes

After fm triggers the context menu, pressing Escape correctly closes the context menu. However, the pending f motion appears to remain active.

For example:

  1. Press v to enter visual mode.
  2. Press m, which opens the context menu.
  3. Press Escape to close the context menu.
  4. Press h.

The h is then treated as the target character for the previous f motion, causing the highlight to move to the next h.

This suggests taht the pending f motion is not being cleared when the context menu interaction occurs.

Suggested Solution

Give a pending Vim f motion higher input priority than the context menu shortcut in visual mode.

When f is awaiting a target character, the next character should be consumed by the Vim motion handler. This would allow fm to find and highlight the next m, while pressing m normally would continue to trigger the context menu.

This preserves the existing context menu shortcut while allowing f{char} motions to work correctly.

Activity

  1. adibhanna commented on Aug 10, 2026

    @adibhanna
    Contributor

    Thanks for the unusually precise report: the leak observation (Escape after the menu, then h getting swallowed as the f target) was the detail that pointed at the real layer.

    What happened: the visual-mode m context-menu shortcut lives in a window-level keydown listener registered with capture, so it runs before CodeMirror's vim plugin ever sees the event and stops propagation. Vim had already gone pending on f, the m was intercepted for the menu, and the still-pending motion then consumed the first key after the menu closed. Both symptoms, one interception.

    Fixed in 9eedf1b on the v2.27.0 branch, along the lines you suggested: the shortcut now checks the vim plugin's own pending state (awaiting a target character after f/t/r, or any buffered prefix like a count or a register) and yields the key to vim when a sequence is in flight. So:

    • v f m extends the selection to the next m.
    • d f m, 2 f m, r m and friends all keep their operand too.
    • A plain m in visual mode still opens the context menu, and the dedicated context-menu key is untouched.
    • The stale-pending leak is gone structurally: the menu can no longer open mid-sequence.

    How to test locally once it ships (or from the branch): with vim mode on, open a note containing a line like alpha m bravo, press 0 then v then f then m. Before: the context menu opens and the selection stays put (and after Escape, the next key jumps the selection). After: the selection extends through the m of "alpha m", no menu. Then press Escape, 0, v, m: the context menu opens as before.

    Ships in 2.27.0.

  2. adibhanna commented on Aug 10, 2026

    @adibhanna
    Contributor

    Closing as fixed by 9eedf1b on the v2.27.0 branch; ships with 2.27.0.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions