Skip to content

Add yank-last-arg to Vi insert mode via Meta-'.' and Meta-'_' - #2178

Open
leo7martins wants to merge 1 commit into
prompt-toolkit:mainfrom
leo7martins:vi-yank-last-arg
Open

leo7martins wants to merge 1 commit into
prompt-toolkit:mainfrom
leo7martins:vi-yank-last-arg

Conversation

@leo7martins

@leo7martins leo7martins commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes #1905.

yank-last-arg has been available to Emacs users since #343; this enables it for Vi insert mode too, so Meta-'.' and Meta-'_' insert the last argument of the previous entry:

@handle("escape", ".", filter=vi_insert_mode)(get_by_name("yank-last-arg"))
@handle("escape", "_", filter=vi_insert_mode)(get_by_name("yank-last-arg"))

This matches both:

  • the Emacs-side bindings (bindings/emacs.py registers the same two sequences), and
  • readline's default vi-insert behavior - in bash/zsh with set -o vi, M-./M-_ are bound to yank-last-arg in vi insert mode as well (bind -m vi-insert -p | grep yank-last-arg).

Notes:

  • The bindings are filtered to Vi insert mode, so navigation mode is untouched ('.' stays free there, matching vi-mode: missing dot "repeat" keybinding #503's future dot-repeat) and selection mode is unaffected.
  • Vi navigation on plain Escape keeps working as before; like in readline, Escape in insert mode is also a meta-prefix when followed quickly by '.'/'_'. Keys that follow Escape behave as before (they are re-processed in the mode Escape switches to).

Tests: test_vi_yank_last_arg in tests/test_cli.py feeds a Vi-mode prompt with prior history and checks that Meta-'.' and Meta-'_' each yank the last word of the previous entry. Full suite: 157 passed with the change.

This change and its tests were prepared with an AI coding assistant (Mistral Vibe). The AI assistant ran test_vi_yank_last_arg and the full test suite (157 passed), and performed the readline behavior comparison. GitHub Actions CI also passed all six Ubuntu jobs on Python 3.10, 3.11, 3.12, 3.13, 3.14, and 3.14t.

Bind the existing yank-last-arg named command ('escape'+'.' and
'escape'+'_') in Vi insert mode, matching the Emacs bindings and
readline's default vi-insert behavior (bash 'set -o vi' users get
M-./M-_ for yank-last-arg as well).

Fixes prompt-toolkit#1905.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
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.

Enable yank-last-arg for Vi binding

1 participant