From 2d2efc8b2ece97384bf08fc55c0eb35eaa86fb5f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 19 Dec 2020 14:26:13 -0800 Subject: [PATCH] Implement o and O bindings for vi mode Credit to @joallard for the patch. Fixes #7442 --- share/functions/fish_vi_key_bindings.fish | 2 ++ src/input.cpp | 2 ++ src/input_common.h | 2 ++ src/reader.cpp | 20 ++++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index e8ff5734f..9224f2283 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -80,6 +80,8 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M default l forward-char bind -s --preset -m insert \n execute bind -s --preset -m insert \r execute + bind -s --preset -m insert o insert-line-under repaint-mode + bind -s --preset -m insert O insert-line-above repaint-mode bind -s --preset -m insert i repaint-mode bind -s --preset -m insert I beginning-of-line repaint-mode bind -s --preset -m insert a forward-single-char repaint-mode diff --git a/src/input.cpp b/src/input.cpp index 27d8bfc1d..8bfb1452c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -140,6 +140,8 @@ static const input_function_metadata_t input_function_metadata[] = { {readline_cmd_t::swap_selection_start_stop, L"swap-selection-start-stop"}, {readline_cmd_t::end_selection, L"end-selection"}, {readline_cmd_t::kill_selection, L"kill-selection"}, + {readline_cmd_t::insert_line_under, L"insert-line-under"}, + {readline_cmd_t::insert_line_above, L"insert-line-above"}, {readline_cmd_t::forward_jump, L"forward-jump"}, {readline_cmd_t::backward_jump, L"backward-jump"}, {readline_cmd_t::forward_jump_till, L"forward-jump-till"}, diff --git a/src/input_common.h b/src/input_common.h index 7e8dc4768..5dbd336b5 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -65,6 +65,8 @@ enum class readline_cmd_t { swap_selection_start_stop, end_selection, kill_selection, + insert_line_under, + insert_line_above, forward_jump, backward_jump, forward_jump_till, diff --git a/src/reader.cpp b/src/reader.cpp index 7fc8d30c5..4a37bce48 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3590,6 +3590,26 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat } break; } + case rl::insert_line_above: { + editable_line_t *el = active_edit_line(); + while (el->position() > 0 && el->text().at(el->position() - 1) != L'\n') { + update_buff_pos(el, el->position() - 1); + } + insert_char(el, L'\n'); + update_buff_pos(el, el->position() - 1); + break; + } + case rl::insert_line_under: { + editable_line_t *el = active_edit_line(); + if (el->position() < el->size()) { + const wchar_t *buff = el->text().c_str(); + while (buff[el->position()] && buff[el->position()] != L'\n') { + update_buff_pos(el, el->position() + 1); + } + } + insert_char(el, L'\n'); + break; + } case rl::forward_jump: case rl::backward_jump: case rl::forward_jump_till: