diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 86d57d905b..8425a475d6 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -2083,6 +2083,14 @@ def finish end private def vi_yank(key) + @waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff| + if byte_pointer_diff > 0 + cut = @line.byteslice(@byte_pointer, byte_pointer_diff) + elsif byte_pointer_diff < 0 + cut = @line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff) + end + copy_for_vi(cut) + } end private def vi_list_or_eof(key) diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index a244927999..6f318db46c 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -1276,4 +1276,22 @@ def test_unimplemented_vi_command_should_be_no_op assert_cursor_max(3) assert_line('abc') end + + def test_vi_yank + input_keys("foo bar\C-[0") + assert_line('foo bar') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(7) + input_keys('y3l') + assert_line('foo bar') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(7) + input_keys('P') + assert_line('foofoo bar') + assert_byte_pointer_size('fo') + assert_cursor(2) + assert_cursor_max(10) + end end