From 9482527f346bd147d75db1465c12c3814c1ce485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 18 May 2022 15:32:51 -0400 Subject: [PATCH] feat(term): uniformize word-wise movement and deletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ctrl-based shortcuts are common in numerous applications. This change: - Adds Ctrl+{Left/Right/Backspace/Delete} for word-wise movement/deletion in prompt, picker, … - Removes Alt-Left and Alt-Right in prompt, picker, … - Adds Alt-Delete in insert mode for forward word deletion In some terminals, Alt-Backspace might not work because it is ambigous. See: https://github.com/helix-editor/helix/pull/2193#issuecomment-1105042501 Hence, Alt alternative is not removed. --- book/src/keymap.md | 90 ++++++++++++++++---------------- helix-term/src/application.rs | 2 +- helix-term/src/keymap/default.rs | 1 + helix-term/src/ui/prompt.rs | 8 +-- 4 files changed, 51 insertions(+), 50 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index 9d5d084177898..bc7baa9a84125 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -289,30 +289,30 @@ convenience. These can be helpful for making simple modifications without escaping to normal mode, but beware that you will not have an undo-able "save point" until you return to normal mode. -| 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` | Delete previous word | `delete_word_backward` | -| `Alt-d` | Delete next word | `delete_word_forward` | -| `Alt-b`, `Ctrl-Left` | Backward a word | `move_prev_word_end` | -| `Ctrl-b`, `Left` | Backward a char | `move_char_left` | -| `Alt-f`, `Ctrl-Right` | Forward a word | `move_next_word_start` | -| `Ctrl-f`, `Right` | Forward a char | `move_char_right` | -| `Ctrl-e`, `End` | Move to line end | `goto_line_end_newline` | -| `Ctrl-a`, `Home` | Move to line start | `goto_line_start` | -| `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` | -| `Ctrl-p`, `Up` | Move to previous line | `move_line_up` | -| `Ctrl-n`, `Down` | Move to next line | `move_line_down` | -| `PageUp` | Move one page up | `page_up` | -| `PageDown` | Move one page down | `page_down` | -| `Alt->` | Go to end of buffer | `goto_file_end` | -| `Alt-<` | Go to start of buffer | `goto_file_start` | +| 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` | +| `Alt-b`, `Ctrl-Left` | Backward a word | `move_prev_word_end` | +| `Ctrl-b`, `Left` | Backward a char | `move_char_left` | +| `Alt-f`, `Ctrl-Right` | Forward a word | `move_next_word_start` | +| `Ctrl-f`, `Right` | Forward a char | `move_char_right` | +| `Ctrl-e`, `End` | Move to line end | `goto_line_end_newline` | +| `Ctrl-a`, `Home` | Move to line start | `goto_line_start` | +| `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` | +| `Ctrl-p`, `Up` | Move to previous line | `move_line_up` | +| `Ctrl-n`, `Down` | Move to next line | `move_line_down` | +| `PageUp` | Move one page up | `page_up` | +| `PageDown` | Move one page down | `page_down` | +| `Alt->` | Go to end of buffer | `goto_file_end` | +| `Alt-<` | Go to start of buffer | `goto_file_start` | ## Select / extend mode @@ -349,25 +349,25 @@ Keys to use within picker. Remapping currently not supported. Keys to use within prompt, Remapping currently not supported. -| Key | Description | -| ----- | ------------- | -| `Escape`, `Ctrl-c` | Close prompt | -| `Alt-b`, `Alt-Left` | Backward a word | -| `Ctrl-b`, `Left` | Backward a char | -| `Alt-f`, `Alt-Right` | Forward a word | -| `Ctrl-f`, `Right` | Forward a char | -| `Ctrl-e`, `End` | Move prompt end | -| `Ctrl-a`, `Home` | Move prompt start | -| `Ctrl-w` | Delete previous word | -| `Alt-d` | Delete next word | -| `Ctrl-u` | Delete to start of line | -| `Ctrl-k` | Delete to end of line | -| `backspace`, `Ctrl-h` | Delete previous char | -| `delete`, `Ctrl-d` | Delete next char | -| `Ctrl-s` | Insert a word under doc cursor, may be changed to Ctrl-r Ctrl-w later | -| `Ctrl-p`, `Up` | Select previous history | -| `Ctrl-n`, `Down` | Select next history | -| `Tab` | Select next completion item | -| `BackTab` | Select previous completion item | -| `Enter` | Open selected | +| Key | Description | +| ----- | ------------- | +| `Escape`, `Ctrl-c` | Close prompt | +| `Alt-b`, `Ctrl-Left` | Backward a word | +| `Ctrl-b`, `Left` | Backward a char | +| `Alt-f`, `Ctrl-Right` | Forward a word | +| `Ctrl-f`, `Right` | Forward a char | +| `Ctrl-e`, `End` | Move prompt end | +| `Ctrl-a`, `Home` | Move prompt start | +| `Ctrl-w`, `Alt-Backspace`, `Ctrl-Backspace` | Delete previous word | +| `Alt-d`, `Alt-Delete`, `Ctrl-Delete` | Delete next word | +| `Ctrl-u` | Delete to start of line | +| `Ctrl-k` | Delete to end of line | +| `backspace`, `Ctrl-h` | Delete previous char | +| `delete`, `Ctrl-d` | Delete next char | +| `Ctrl-s` | Insert a word under doc cursor, may be changed to Ctrl-r Ctrl-w later | +| `Ctrl-p`, `Up` | Select previous history | +| `Ctrl-n`, `Down` | Select next history | +| `Tab` | Select next completion item | +| `BackTab` | Select previous completion item | +| `Enter` | Open selected | diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 2dfccf0435ecd..547fdd9f9b596 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -290,7 +290,7 @@ impl Application { } fn refresh_config(&mut self) { - let config = Config::load(helix_loader::config_file()).unwrap_or_else(|err| { + let config = Config::load_default().unwrap_or_else(|err| { self.editor.set_error(err.to_string()); Config::default() }); diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index a8ff8be91bf6e..419279f086997 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -326,6 +326,7 @@ pub fn default() -> HashMap { "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, "left" => move_char_left, diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index ef08edf2d836f..fc65e9877a2e2 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -459,14 +459,14 @@ impl Component for Prompt { (self.callback_fn)(cx, &self.line, PromptEvent::Abort); return close_fn; } - alt!('b') | alt!(Left) => self.move_cursor(Movement::BackwardWord(1)), - alt!('f') | alt!(Right) => self.move_cursor(Movement::ForwardWord(1)), + alt!('b') | ctrl!(Left) => self.move_cursor(Movement::BackwardWord(1)), + alt!('f') | ctrl!(Right) => self.move_cursor(Movement::ForwardWord(1)), ctrl!('b') | key!(Left) => self.move_cursor(Movement::BackwardChar(1)), ctrl!('f') | key!(Right) => self.move_cursor(Movement::ForwardChar(1)), ctrl!('e') | key!(End) => self.move_end(), ctrl!('a') | key!(Home) => self.move_start(), - ctrl!('w') => self.delete_word_backwards(cx), - alt!('d') => self.delete_word_forwards(cx), + ctrl!('w') | alt!(Backspace) | ctrl!(Backspace) => self.delete_word_backwards(cx), + alt!('d') | alt!(Delete) | ctrl!(Delete) => self.delete_word_forwards(cx), ctrl!('k') => self.kill_to_end_of_line(cx), ctrl!('u') => self.kill_to_start_of_line(cx), ctrl!('h') | key!(Backspace) => {