From 8093612cac11f0067c14a9dae775d0a6f8534426 Mon Sep 17 00:00:00 2001 From: Ludwig Stecher Date: Tue, 31 Dec 2019 05:06:36 +0100 Subject: [PATCH] Allow moving in text with Ctrl+ArrowLeft, Ctrl+ArrowRight (#1141) * Allow moving in text with Ctrl+ArrowLeft, Ctrl+ArrowRight * Document changes * Format --- src/cli.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 0551e246c1..c3af9debe6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -17,7 +17,10 @@ use nu_protocol::{Signature, UntaggedValue, Value}; use log::{debug, log_enabled, trace}; use rustyline::error::ReadlineError; -use rustyline::{self, config::Configurer, config::EditMode, ColorMode, Config, Editor}; +use rustyline::{ + self, config::Configurer, config::EditMode, At, Cmd, ColorMode, Config, Editor, KeyPress, + Movement, Word, +}; use std::error::Error; use std::io::{BufRead, BufReader, Write}; use std::iter::Iterator; @@ -351,6 +354,16 @@ pub async fn cli() -> Result<(), Box> { let config = Config::builder().color_mode(ColorMode::Forced).build(); let mut rl: Editor<_> = Editor::with_config(config); + // add key bindings to move over a whole word with Ctrl+ArrowLeft and Ctrl+ArrowRight + rl.bind_sequence( + KeyPress::ControlLeft, + Cmd::Move(Movement::BackwardWord(1, Word::Vi)), + ); + rl.bind_sequence( + KeyPress::ControlRight, + Cmd::Move(Movement::ForwardWord(1, At::AfterEnd, Word::Vi)), + ); + #[cfg(windows)] { let _ = ansi_term::enable_ansi_support();