Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/prompt_toolkit/key_binding/bindings/vi.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ def load_vi_bindings() -> KeyBindingsBase:
# Insert a character literally (quoted insert).
handle("c-v", filter=vi_insert_mode)(get_by_name("quoted-insert"))

# Yank the last argument of the previous entry, like the Emacs
# bindings and readline's default Vi-insert bindings. (Issue #1905.)
handle("escape", ".", filter=vi_insert_mode)(get_by_name("yank-last-arg"))
handle("escape", "_", filter=vi_insert_mode)(get_by_name("yank-last-arg"))

@handle("escape")
def _back_to_navigation(event: E) -> None:
"""
Expand Down
20 changes: 20 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,23 @@ def test_accept_default():
# prompt reset between calls happened at the wrong time, breaking this.)
result = session.prompt(default="world", accept_default=True)
assert result == "world"


def test_vi_yank_last_arg():
"""
In Vi insert mode, Meta-'.' and Meta-'_' yank the last argument of the
previous entry, like the Emacs bindings and readline's default
Vi-insert bindings. (Issue #1905.)
"""
history = InMemoryHistory()
history.append_string("first one two")

feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI, history=history)

# Meta-'.' inserts the last word of the previous entry.
result, cli = feed("test \x1b.\r")
assert result.text == "test two"

# Alias: Meta-'_'.
result, cli = feed("test \x1b_\r")
assert result.text == "test two"
Loading