Allow moving in text with Ctrl+ArrowLeft, Ctrl+ArrowRight (#1141)

* Allow moving in text with Ctrl+ArrowLeft, Ctrl+ArrowRight

* Document changes

* Format
This commit is contained in:
Ludwig Stecher 2019-12-31 05:06:36 +01:00 committed by Jonathan Turner
parent f37f29b441
commit 8093612cac

View File

@ -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<dyn Error>> {
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();