diff --git a/yazi-config/preset/keymap-default.toml b/yazi-config/preset/keymap-default.toml index 1224881f..e45875ac 100644 --- a/yazi-config/preset/keymap-default.toml +++ b/yazi-config/preset/keymap-default.toml @@ -249,11 +249,14 @@ keymap = [ { on = "", run = "move 1", desc = "Move forward a character" }, # Word-wise movement - { on = "b", run = "backward", desc = "Move back to the start of the current or previous word" }, - { on = "w", run = "forward", desc = "Move forward to the start of the next word" }, - { on = "e", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" }, - { on = "", run = "backward", desc = "Move back to the start of the current or previous word" }, - { on = "", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" }, + { on = "b", run = "backward", desc = "Move back to the start of the current or previous word" }, + { on = "w", run = "forward", desc = "Move forward to the start of the next word" }, + { on = "e", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" }, + { on = "B", run = "backward --big", desc = "Move back to the start of the current or previous WORD" }, + { on = "W", run = "forward --big", desc = "Move forward to the start of the next WORD" }, + { on = "E", run = "forward --big --end-of-word", desc = "Move forward to the end of the current or next WORD" }, + { on = "", run = "backward", desc = "Move back to the start of the current or previous word" }, + { on = "", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" }, # Line-wise movement { on = "0", run = "move bol", desc = "Move to the BOL" }, diff --git a/yazi-core/src/input/commands/backward.rs b/yazi-core/src/input/commands/backward.rs index 3a69c88b..aff30ae4 100644 --- a/yazi-core/src/input/commands/backward.rs +++ b/yazi-core/src/input/commands/backward.rs @@ -2,8 +2,18 @@ use yazi_shared::{CharKind, event::CmdCow}; use crate::input::Input; +struct Opt { + big: bool, +} + +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { big: c.bool("big") } + } +} + impl Input { - pub fn backward(&mut self, _: CmdCow) { + #[yazi_codegen::command] + pub fn backward(&mut self, opt: Opt) { let snap = self.snap(); if snap.cursor == 0 { return self.move_(0); @@ -14,7 +24,12 @@ impl Input { let mut prev = CharKind::new(it.next().unwrap().1); for (i, c) in it { let c = CharKind::new(c); - if prev != CharKind::Space && prev != c { + let new_char_kind = if opt.big { + (c == CharKind::Space) != (prev == CharKind::Space) + } else { + c != prev + }; + if prev != CharKind::Space && new_char_kind { return self.move_(-(i as isize)); } prev = c; diff --git a/yazi-core/src/input/commands/forward.rs b/yazi-core/src/input/commands/forward.rs index f27b2520..1cb15e2c 100644 --- a/yazi-core/src/input/commands/forward.rs +++ b/yazi-core/src/input/commands/forward.rs @@ -4,10 +4,16 @@ use crate::input::{Input, op::InputOp}; struct Opt { end_of_word: bool, + big: bool, } impl From for Opt { - fn from(c: CmdCow) -> Self { Self { end_of_word: c.bool("end-of-word") } } + fn from(c: CmdCow) -> Self { + Self { + end_of_word: c.bool("end-of-word"), + big: c.bool("big"), + } + } } impl Input { @@ -22,10 +28,15 @@ impl Input { for (i, c) in it { let c = CharKind::new(c); - let b = if opt.end_of_word { - prev != CharKind::Space && prev != c && i != 1 + let new_char_kind = if opt.big { + (c == CharKind::Space) != (prev == CharKind::Space) } else { - c != CharKind::Space && c != prev + c != prev + }; + let b = if opt.end_of_word { + prev != CharKind::Space && new_char_kind && i != 1 + } else { + c != CharKind::Space && new_char_kind }; if b && !matches!(snap.op, InputOp::None | InputOp::Select(_)) { return self.move_(i as isize);