From e0785aabe7618d5211f258a058bf08892ff04d06 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 24 Sep 2020 19:16:35 +0900 Subject: Move-by-word commands: w, b, e. --- helix-view/src/commands.rs | 35 +++++++++++++++++++++++++++++++++++ helix-view/src/keymap.rs | 12 ++++++++++++ 2 files changed, 47 insertions(+) (limited to 'helix-view/src') diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 560167c9..be3ea0b9 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -39,6 +39,41 @@ pub fn move_line_down(view: &mut View, count: usize) { .move_selection(Direction::Forward, Granularity::Line, count); } +pub fn move_next_word_start(view: &mut View, count: usize) { + let pos = view.state.move_pos( + view.state.selection.cursor(), + Direction::Forward, + Granularity::Word, + count, + ); + + // TODO: use a transaction + view.state.selection = Selection::single(pos, pos); +} + +pub fn move_prev_word_start(view: &mut View, count: usize) { + let pos = view.state.move_pos( + view.state.selection.cursor(), + Direction::Backward, + Granularity::Word, + count, + ); + + // TODO: use a transaction + view.state.selection = Selection::single(pos, pos); +} + +pub fn move_next_word_end(view: &mut View, count: usize) { + let pos = State::move_next_word_end( + &view.state.doc().slice(..), + view.state.selection.cursor(), + count, + ); + + // TODO: use a transaction + view.state.selection = Selection::single(pos, pos); +} + // avoid select by default by having a visual mode switch that makes movements into selects // insert mode: diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index 705357a8..9fabf41d 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -102,6 +102,18 @@ pub fn default() -> Keymaps { code: KeyCode::Char('l'), modifiers: Modifiers::NONE }] => commands::move_char_right as Command, + vec![Key { + code: KeyCode::Char('w'), + modifiers: Modifiers::NONE + }] => commands::move_next_word_start as Command, + vec![Key { + code: KeyCode::Char('b'), + modifiers: Modifiers::NONE + }] => commands::move_prev_word_start as Command, + vec![Key { + code: KeyCode::Char('e'), + modifiers: Modifiers::NONE + }] => commands::move_next_word_end as Command, vec![Key { code: KeyCode::Char('i'), modifiers: Modifiers::NONE -- cgit v1.2.3-70-g09d2