Skip to content

fix: preserve typeahead order on multi-key sequences#20

Merged
zuqini merged 1 commit into
zuqini:mainfrom
yavorski:main
May 13, 2026
Merged

fix: preserve typeahead order on multi-key sequences#20
zuqini merged 1 commit into
zuqini:mainfrom
yavorski:main

Conversation

@yavorski

Copy link
Copy Markdown
Contributor

Fix: lazy keys break multi-key sequences (e.g. vib)

Problem

When a plugin is lazy-loaded by a key like i (mode x/o), pressing a multi-key sequence such as vib does not work on the first invocation. It behaves as if only vb was pressed.

Repro with mini.ai:

{
  "nvim-mini/mini.ai",
  keys = {
    { "a", mode = { "x", "o" } },
    { "i", mode = { "x", "o" } },
  },
  config = function() require("mini.ai").setup() end,
}

Full config example here

Place cursor inside { "a", "b", "c" }, press vib — selection fails.
It behaves as if only vb was pressed (visual mode, then move back a word).
It works on second try because plugin already loaded.

Cause

In lua/zpack/lazy_trigger/keys.lua the proxy re-feeds the lhs with:

vim.api.nvim_feedkeys(vim.keycode(lhs), 'm', false)

The 'm' flag appends to the typeahead. When pressing vib:

  1. v enters visual
  2. i fires the proxy; b is already queued in typeahead
  3. proxy appends i → final order becomes b, i
  4. b runs first (move back word) — observed behavior is vb

lazy.nvim solves this with the 'i' flag (insert at front) — see lazy/core/handler/keys.lua#L140.

Fix

One-character change: 'm''i'.

Test

Added a brief regression test in tests/lazy_keys_test.lua.
Fails on old code, passes after the fix. All 333 → 334 tests pass.

The lazy-keys proxy used `nvim_feedkeys` with the `m` flag which appends to the typeahead buffer.

For multi-key sequences like `vib`, the trailing `b` was already queued when the proxy fired on `i`, so appending `i` produced the order `b`, `i` instead of `i`, `b`.

Result: pressing `vib` behave like `vb`.

Switch to the `i` flag to insert at the front, matching lazy.nvim behavior (see lazy/core/handler/keys.lua:140).

@zuqini zuqini left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the contribution!

@zuqini
zuqini merged commit 79f2ea9 into zuqini:main May 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants