diff --git a/book/src/keymap.md b/book/src/keymap.md index a3e41666f3fd..f5e9f104dd7c 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -113,6 +113,7 @@ Normal mode is the default mode when you launch helix. You can return to it from | `s` | Select all regex matches inside selections | `select_regex` | | `S` | Split selection into sub selections on regex matches | `split_selection` | | `Alt-s` | Split selection on newlines | `split_selection_on_newline` | +| `Alt-S` | Select first and last characters of each selection | `select_first_and_last_chars` | | `Alt-minus` | Merge selections | `merge_selections` | | `Alt-_` | Merge consecutive selections | `merge_consecutive_selections` | | `&` | Align selection in columns | `align_selections` | diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4df3278b8bba..25d4da21a848 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -278,6 +278,7 @@ impl MappableCommand { half_page_up, "Move half page up", half_page_down, "Move half page down", select_all, "Select whole document", + select_first_and_last_chars, "Select first and last characters of each selection", select_regex, "Select all regex matches inside selections", split_selection, "Split selections on regex matches", split_selection_on_newline, "Split selection on newlines", @@ -1811,6 +1812,21 @@ fn select_all(cx: &mut Context) { doc.set_selection(view.id, Selection::single(0, end)) } +fn select_first_and_last_chars(cx: &mut Context) { + let (view, doc) = current!(cx.editor); + let text = doc.text().slice(..); + + let selection = doc.selection(view.id).clone().transform_iter(|range| { + [ + Range::point(range.from()), + Range::point(graphemes::prev_grapheme_boundary(text, range.to())), + ] + .into_iter() + }); + + doc.set_selection(view.id, selection); +} + fn select_regex(cx: &mut Context) { let reg = cx.register.unwrap_or('/'); ui::regex_prompt( diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 763ed4ae71ce..6a35581a774a 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -78,6 +78,7 @@ pub fn default() -> HashMap { "s" => select_regex, + "A-S" => select_first_and_last_chars, "A-s" => split_selection_on_newline, "A-minus" => merge_selections, "A-_" => merge_consecutive_selections,