Skip to content

Commit 237f559

Browse files
committed
Use vi-specific backward word logic
Use vi_backward_word on b key in vi mode as the original emacs mode implementation respects different word boundaries.
1 parent 23babd6 commit 237f559

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Lib/_pyrepl/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def make_default_commands() -> dict[CommandName, type[Command]]:
157157
(r"0", "beginning-of-line"),
158158
(r"$", "end-of-line"),
159159
(r"w", "vi-forward-word"),
160-
(r"b", "backward-word"),
160+
(r"b", "vi-backward-word"),
161161
(r"e", "end-of-word"),
162162
(r"^", "first-non-whitespace-character"),
163163

Lib/_pyrepl/vi_commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def do(self) -> None:
2828
r.pos = r.vi_forward_word()
2929

3030

31+
class vi_backward_word(MotionCommand):
32+
def do(self) -> None:
33+
r = self.reader
34+
for _ in range(r.get_arg()):
35+
r.pos = r.vi_bow()
36+
37+
3138
# ============================================================================
3239
# Mode Switching Commands
3340
# ============================================================================

Lib/test/test_pyrepl/test_reader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ def test_vi_word_boundaries(self):
10111011
("foo.bar", "0e", 2, "e lands on last o of foo"),
10121012
("foo.bar", "0ee", 3, "second e lands on dot"),
10131013
("foo.bar", "0eee", 6, "third e lands on last r of bar"),
1014+
1015+
# Backward word (b) - cursor at end after ESC
1016+
("foo bar", "$b", 4, "b from end lands on bar"),
1017+
("foo bar", "$bb", 0, "two b's lands on foo"),
1018+
("foo.bar", "$b", 4, "b from end lands on bar"),
1019+
("foo.bar", "$bb", 3, "second b lands on dot"),
1020+
("foo.bar", "$bbb", 0, "third b lands on foo"),
1021+
("get_value(x)", "$b", 10, "b from end lands on x"),
1022+
("get_value(x)", "$bb", 9, "second b lands on ("),
1023+
("get_value(x)", "$bbb", 0, "third b lands on get_value"),
10141024
]
10151025

10161026
for text, keys, expected_pos, desc in test_cases:

0 commit comments

Comments
 (0)