From 3d59d3f8be214ddb5b75d6a9df5f0ea1fff5f31c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 3 Oct 2022 23:08:15 +0800 Subject: [PATCH] Keep arrow and special keys in insert (#3915) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Keep arrow and special keys in insert Advanced users won't need it and is useful for beginners. Revert part of #3671. * Change text for insert mode section Co-authored-by: Blaž Hrastnik * Remove ctrl-up/down in insert * Reorganize insert keys and docs * Improve page up experience on last tutor The last tutor page can page down multiple times and it will break the heading on the 80x24 screen paging when reaching the last page, this keeps the style the same and make sure page up and down won't break it. Co-authored-by: Blaž Hrastnik --- book/src/keymap.md | 68 +++++++++++++------------------- helix-term/src/keymap/default.rs | 31 ++++++++------- runtime/tutor | 18 +++++++++ 3 files changed, 63 insertions(+), 54 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index 905d3acb6..666022332 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -314,7 +314,7 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire | `[space` | Add newline above | `add_newline_above` | | `]space` | Add newline below | `add_newline_below` | -## Insert Mode +## Insert mode Insert mode bindings are somewhat minimal by default. Helix is designed to be a modal editor, and this is reflected in the user experience and internal @@ -323,45 +323,33 @@ escaping from insert mode to normal mode. For this reason, new users are strongly encouraged to learn the modal editing paradigm to get the smoothest experience. -| Key | Description | Command | -| ----- | ----------- | ------- | -| `Escape` | Switch to normal mode | `normal_mode` | -| `Ctrl-x` | Autocomplete | `completion` | -| `Ctrl-r` | Insert a register content | `insert_register` | -| `Ctrl-w`, `Alt-Backspace`, `Ctrl-Backspace` | Delete previous word | `delete_word_backward` | -| `Alt-d`, `Alt-Delete`, `Ctrl-Delete` | Delete next word | `delete_word_forward` | -| `Ctrl-u` | Delete to start of line | `kill_to_line_start` | -| `Ctrl-k` | Delete to end of line | `kill_to_line_end` | -| `Ctrl-j`, `Enter` | Insert new line | `insert_newline` | -| `Backspace`, `Ctrl-h` | Delete previous char | `delete_char_backward` | -| `Delete`, `Ctrl-d` | Delete next char | `delete_char_forward` | - -However, if you really want navigation in insert mode, this is supported. An -example config that gives the ability to use arrow keys while still in insert -mode: - -```toml -[keys.insert] -"up" = "move_line_up" -"down" = "move_line_down" -"left" = "move_char_left" -"right" = "move_char_right" -"C-b" = "move_char_left" -"C-f" = "move_char_right" -"A-b" = "move_prev_word_end" -"C-left" = "move_prev_word_end" -"A-f" = "move_next_word_start" -"C-right" = "move_next_word_start" -"A-<" = "goto_file_start" -"A->" = "goto_file_end" -"pageup" = "page_up" -"pagedown" = "page_down" -"home" = "goto_line_start" -"C-a" = "goto_line_start" -"end" = "goto_line_end_newline" -"C-e" = "goto_line_end_newline" -"A-left" = "goto_line_start" -``` +| Key | Description | Command | +| ----- | ----------- | ------- | +| `Escape` | Switch to normal mode | `normal_mode` | +| `Ctrl-s` | Commit undo checkpoint | `commit_undo_checkpoint` | +| `Ctrl-x` | Autocomplete | `completion` | +| `Ctrl-r` | Insert a register content | `insert_register` | +| `Ctrl-w`, `Alt-Backspace` | Delete previous word | `delete_word_backward` | +| `Alt-d`, `Alt-Delete` | Delete next word | `delete_word_forward` | +| `Ctrl-u` | Delete to start of line | `kill_to_line_start` | +| `Ctrl-k` | Delete to end of line | `kill_to_line_end` | +| `Ctrl-h`, `Backspace` | Delete previous char | `delete_char_backward` | +| `Ctrl-d`, `Delete` | Delete next char | `delete_char_forward` | +| `Ctrl-j`, `Enter` | Insert new line | `insert_newline` | + +These keys are not recommended, but are included for new users less familiar +with modal editors. + +| Key | Description | Command | +| ----- | ----------- | ------- | +| `Up` | Move to previous line | `move_line_up` | +| `Down` | Move to next line | `move_line_down` | +| `Left` | Backward a char | `move_char_left` | +| `Right` | Forward a char | `move_char_right` | +| `PageUp` | Move one page up | `page_up` | +| `PageDown` | Move one page down | `page_down` | +| `Home` | Move to line start | `goto_line_start` | +| `End` | Move to line end | `goto_line_end_newline` | ## Select / extend mode diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 4da609ec4..6c327ee6b 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -343,24 +343,27 @@ pub fn default() -> HashMap { let insert = keymap!({ "Insert mode" "esc" => normal_mode, - "backspace" => delete_char_backward, - "C-h" => delete_char_backward, - "del" => delete_char_forward, - "C-d" => delete_char_forward, - "ret" => insert_newline, - "C-j" => insert_newline, - "tab" => insert_tab, - "C-w" => delete_word_backward, - "A-backspace" => delete_word_backward, - "A-d" => delete_word_forward, - "A-del" => delete_word_forward, "C-s" => commit_undo_checkpoint, + "C-x" => completion, + "C-r" => insert_register, - "C-k" => kill_to_line_end, + "C-w" | "A-backspace" => delete_word_backward, + "A-d" | "A-del" => delete_word_forward, "C-u" => kill_to_line_start, + "C-k" => kill_to_line_end, + "C-h" | "backspace" => delete_char_backward, + "C-d" | "del" => delete_char_forward, + "C-j" | "ret" => insert_newline, + "tab" => insert_tab, - "C-x" => completion, - "C-r" => insert_register, + "up" => move_line_up, + "down" => move_line_down, + "left" => move_char_left, + "right" => move_char_right, + "pageup" => page_up, + "pagedown" => page_down, + "home" => goto_line_start, + "end" => goto_line_end_newline, }); hashmap!( Mode::Normal => Keymap::new(normal), diff --git a/runtime/tutor b/runtime/tutor index 8eef33af2..7133c4896 100644 --- a/runtime/tutor +++ b/runtime/tutor @@ -1054,6 +1054,24 @@ letters! that is not good grammar. you can fix this. +================================================================= += = +================================================================= + + + + + + + + + + + + + + + ================================================================= This tutorial is still a work-in-progress. More sections are planned.