Skip to content

Commit 8860f83

Browse files
[3.13] gh-119035: Add Ctrl+← and Ctrl+→ word-skipping keybindings to new repl (GH-119248) (#119323)
add word-skipping ctrl keybindings to new repl (cherry picked from commit 0398d93) Co-authored-by: Alastair Stanley <alastairstanley@ntlworld.com>
1 parent 256b791 commit 8860f83

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Diff for: Lib/_pyrepl/keymap.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,12 @@ def _parse_key1(key, s):
177177
ret = key[s]
178178
s += 1
179179
if ctrl:
180-
if len(ret) > 1:
181-
raise KeySpecError("\\C- must be followed by a character")
182-
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
180+
if len(ret) == 1:
181+
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
182+
elif ret in {"left", "right"}:
183+
ret = f"ctrl {ret}"
184+
else:
185+
raise KeySpecError("\\C- followed by invalid key")
183186
if meta:
184187
ret = ["\033", ret]
185188
else:

Diff for: Lib/_pyrepl/reader.py

+2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def make_default_commands() -> dict[CommandName, type[Command]]:
136136
(r"\<up>", "up"),
137137
(r"\<down>", "down"),
138138
(r"\<left>", "left"),
139+
(r"\C-\<left>", "backward-word"),
139140
(r"\<right>", "right"),
141+
(r"\C-\<right>", "forward-word"),
140142
(r"\<delete>", "delete"),
141143
(r"\<backspace>", "backspace"),
142144
(r"\M-\<backspace>", "backward-kill-word"),

0 commit comments

Comments
 (0)