summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-05-27 05:45:08 +0900
committeraycabta <aycabta@gmail.com>2019-05-27 05:45:08 +0900
commit716ba4a12732d94a50fb31bcaca4ce07bc4b6870 (patch)
tree1890bb063616b57e246673f596c8a29e77f63c2d
parent64dc21830aa60dc757df48c715a73f704eed43e0 (diff)
Implement J to join lines in vi command mode
-rw-r--r--lib/reline/key_actor/vi_command.rb2
-rw-r--r--lib/reline/line_editor.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/reline/key_actor/vi_command.rb b/lib/reline/key_actor/vi_command.rb
index ac8458c87c..130fcb04a6 100644
--- a/lib/reline/key_actor/vi_command.rb
+++ b/lib/reline/key_actor/vi_command.rb
@@ -149,7 +149,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 73 I
:vi_insert_at_bol,
# 74 J
- :ed_search_next_history,
+ :vi_join_lines,
# 75 K
:ed_search_prev_history,
# 76 L
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index f4e012688e..83c0d419c3 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -40,6 +40,7 @@ class Reline::LineEditor
vi_paste_prev
vi_paste_next
vi_replace_char
+ vi_join_lines
}
VI_OPERATORS = %i{
@@ -1632,4 +1633,18 @@ class Reline::LineEditor
end
@waiting_proc = nil
end
+
+ private def vi_join_lines(key, arg: 1)
+ if @is_multiline and @buffer_of_lines.size > @line_index + 1
+ @cursor = calculate_width(@line)
+ @byte_pointer = @line.bytesize
+ @line += ' ' + @buffer_of_lines.delete_at(@line_index + 1).gsub(/\A +/, '')
+ @cursor_max = calculate_width(@line)
+ @buffer_of_lines[@line_index] = @line
+ @rerender_all = true
+ @rest_height += 1
+ end
+ arg -= 1
+ vi_join_lines(key, arg: arg) if arg > 0
+ end
end