Skip to content

Commit

Permalink
Implement J to join lines in vi command mode
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed May 26, 2019
1 parent 64dc218 commit 716ba4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reline/key_actor/vi_command.rb
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/reline/line_editor.rb
Expand Up @@ -40,6 +40,7 @@ class Reline::LineEditor
vi_paste_prev
vi_paste_next
vi_replace_char
vi_join_lines
}

VI_OPERATORS = %i{
Expand Down Expand Up @@ -1632,4 +1633,18 @@ def finish
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

0 comments on commit 716ba4a

Please sign in to comment.