diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index 63f96761b4..0bcaf51b39 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -51,6 +51,7 @@ pub struct Config { pub filesize_format: String, pub use_ansi_coloring: bool, pub env_conversions: HashMap, + pub edit_mode: String, } impl Default for Config { @@ -67,6 +68,7 @@ impl Default for Config { filesize_format: "auto".into(), use_ansi_coloring: true, env_conversions: HashMap::new(), // TODO: Add default conversoins + edit_mode: "emacs".into(), } } } @@ -176,6 +178,9 @@ impl Value { config.env_conversions = env_conversions; } + "edit_mode" => { + config.edit_mode = value.as_string()?; + } _ => {} } } diff --git a/src/main.rs b/src/main.rs index efe6bd433c..fdeb165dd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use nu_protocol::{ Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID, }; use reedline::{ - Completer, CompletionActionHandler, DefaultHinter, DefaultPrompt, LineBuffer, Prompt, + Completer, CompletionActionHandler, DefaultHinter, DefaultPrompt, LineBuffer, Prompt, Vi, }; use std::{ io::Write, @@ -354,7 +354,7 @@ fn main() -> Result<()> { //FIXME: if config.use_ansi_coloring is false then we should // turn off the hinter but I don't see any way to do that yet. - let mut line_editor = if let Some(history_path) = history_path.clone() { + let line_editor = if let Some(history_path) = history_path.clone() { let history = std::fs::read_to_string(&history_path); if history.is_ok() { line_editor @@ -375,6 +375,15 @@ fn main() -> Result<()> { line_editor }; + // The line editor default mode is emacs mode. For the moment we only + // need to check for vi mode + let mut line_editor = if config.edit_mode == "vi" { + let edit_mode = Box::new(Vi::default()); + line_editor.with_edit_mode(edit_mode) + } else { + line_editor + }; + let prompt = update_prompt( PROMPT_COMMAND, &engine_state,