1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Implement J to join lines in vi command mode

This commit is contained in:
aycabta 2019-05-27 05:45:08 +09:00
parent 64dc21830a
commit 716ba4a127
2 changed files with 16 additions and 1 deletions

View file

@ -149,7 +149,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 73 I # 73 I
:vi_insert_at_bol, :vi_insert_at_bol,
# 74 J # 74 J
:ed_search_next_history, :vi_join_lines,
# 75 K # 75 K
:ed_search_prev_history, :ed_search_prev_history,
# 76 L # 76 L

View file

@ -40,6 +40,7 @@ class Reline::LineEditor
vi_paste_prev vi_paste_prev
vi_paste_next vi_paste_next
vi_replace_char vi_replace_char
vi_join_lines
} }
VI_OPERATORS = %i{ VI_OPERATORS = %i{
@ -1632,4 +1633,18 @@ class Reline::LineEditor
end end
@waiting_proc = nil @waiting_proc = nil
end 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 end