From 139f7fc367894ab9dd3b5a5ed3d95ea4ff7b47f4 Mon Sep 17 00:00:00 2001 From: David Laban Date: Sat, 9 Sep 2023 16:24:35 +0100 Subject: [PATCH 1/4] make control-w behave like bash 'man bash' documents this as: unix-word-rubout (C-w) Kill the word behind point, using white space as a word boundary. The killed text is saved on the kill-ring. zsh does not have a concept of small/big words, but its 'word' is slightly bigger than nushell's small word, because it includes -./_ and a few other punctuation marks. fish's control-w is slightly larger than nushell's small word in that it seems to delete up to the next / (and doesn't need an extra control-w to delete the '/' 'thing/'). --- src/edit_mode/emacs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/edit_mode/emacs.rs b/src/edit_mode/emacs.rs index 35aa6db7..4897a71b 100644 --- a/src/edit_mode/emacs.rs +++ b/src/edit_mode/emacs.rs @@ -50,7 +50,7 @@ pub fn default_emacs_keybindings() -> Keybindings { KC::Char('y'), edit_bind(EC::PasteCutBufferBefore), ); - kb.add_binding(KM::CONTROL, KC::Char('w'), edit_bind(EC::CutWordLeft)); + kb.add_binding(KM::CONTROL, KC::Char('w'), edit_bind(EC::CutBigWordLeft)); kb.add_binding(KM::CONTROL, KC::Char('k'), edit_bind(EC::CutToEnd)); kb.add_binding(KM::CONTROL, KC::Char('u'), edit_bind(EC::CutFromStart)); // Edits From 27e59eb5e8b444e96d051412263e141e82ba4790 Mon Sep 17 00:00:00 2001 From: David Laban Date: Sat, 9 Sep 2023 16:26:44 +0100 Subject: [PATCH 2/4] make alt+backspace work in vscode by default On MacOS, vscode generates control-alt-h in response to alt+backspace. This is handled in bash as cut-smallword-left and in zsh as cut-word-left (zsh doesn't seem to have a concept of small/big words). Fish treats this as cut small word left (fish bigwords include anything up to /, and its small words stop on any punctuation). --- src/edit_mode/emacs.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/edit_mode/emacs.rs b/src/edit_mode/emacs.rs index 4897a71b..3195a49f 100644 --- a/src/edit_mode/emacs.rs +++ b/src/edit_mode/emacs.rs @@ -51,6 +51,11 @@ pub fn default_emacs_keybindings() -> Keybindings { edit_bind(EC::PasteCutBufferBefore), ); kb.add_binding(KM::CONTROL, KC::Char('w'), edit_bind(EC::CutBigWordLeft)); + kb.add_binding( + KM::CONTROL | KM::ALT, + KC::Char('h'), + edit_bind(EC::CutWordLeft), + ); kb.add_binding(KM::CONTROL, KC::Char('k'), edit_bind(EC::CutToEnd)); kb.add_binding(KM::CONTROL, KC::Char('u'), edit_bind(EC::CutFromStart)); // Edits From b28183c4e784e0ff2f40f753f4aaa1be7f70f432 Mon Sep 17 00:00:00 2001 From: David Laban Date: Sat, 9 Sep 2023 17:56:14 +0100 Subject: [PATCH 3/4] control-w behaviour is not common between vi_insert and emacs --- src/edit_mode/vi/vi_keybindings.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/edit_mode/vi/vi_keybindings.rs b/src/edit_mode/vi/vi_keybindings.rs index 1498f3ac..314baef5 100644 --- a/src/edit_mode/vi/vi_keybindings.rs +++ b/src/edit_mode/vi/vi_keybindings.rs @@ -30,10 +30,15 @@ pub fn default_vi_normal_keybindings() -> Keybindings { /// Default Vi insert keybindings pub fn default_vi_insert_keybindings() -> Keybindings { let mut kb = Keybindings::new(); + use EditCommand as EC; + use KeyCode as KC; + use KeyModifiers as KM; add_common_control_bindings(&mut kb); add_common_navigation_bindings(&mut kb); add_common_edit_bindings(&mut kb); + kb.add_binding(KM::CONTROL, KC::Char('w'), edit_bind(EC::BackspaceWord)); + kb } From 1f64b679d2e4dce18c8c4602f3312d303e52352a Mon Sep 17 00:00:00 2001 From: David Laban Date: Sat, 9 Sep 2023 17:58:40 +0100 Subject: [PATCH 4/4] fixup! control-w behaviour is not common between vi_insert and emacs --- src/edit_mode/keybindings.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/edit_mode/keybindings.rs b/src/edit_mode/keybindings.rs index 772e4199..8d1bea88 100644 --- a/src/edit_mode/keybindings.rs +++ b/src/edit_mode/keybindings.rs @@ -193,5 +193,4 @@ pub fn add_common_edit_bindings(kb: &mut Keybindings) { kb.add_binding(KM::CONTROL, KC::Delete, edit_bind(EC::DeleteWord)); // Base commands should not affect cut buffer kb.add_binding(KM::CONTROL, KC::Char('h'), edit_bind(EC::Backspace)); - kb.add_binding(KM::CONTROL, KC::Char('w'), edit_bind(EC::BackspaceWord)); }