From 6bff8c8e1ad3a230f3cd8f5d7078ed2af3f43463 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 16 Jan 2024 22:35:10 +0900 Subject: feat(search): introduce keymap-dependent vim-mode (#1570) * feat(search): introduce keymap-dependent vim-mode * fix(zsh): provide widgets with specific keymaps * fix(settings): unify "vim" and "keymap_mode" --- atuin-client/config.toml | 9 +++++++-- atuin-client/src/settings.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'atuin-client') diff --git a/atuin-client/config.toml b/atuin-client/config.toml index 29581d1f..24366b60 100644 --- a/atuin-client/config.toml +++ b/atuin-client/config.toml @@ -126,8 +126,13 @@ enter_accept = true -## Defaults to false. If enabled you may use 'j' and 'k' to navigate the history list and 'i' to enter Insert mode. -# vim = false +## Defaults to "emacs". This specifies the keymap on the startup of `atuin +## search`. If this is set to "auto", the startup keymap mode in the Atuin +## search is automatically selected based on the shell's keymap where the +## keybinding is defined. If this is set to "emacs", "vim-insert", or +## "vim-normal", the startup keymap mode in the Atuin search is forced to be +## the specified one. +# keymap_mode = "auto" #[stats] # Set commands where we should consider the subcommand for statistics. Eg, kubectl get vs just kubectl diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index ea01961c..36bbd826 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -143,6 +143,32 @@ pub enum WordJumpMode { Subl, } +#[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum)] +pub enum KeymapMode { + #[serde(rename = "emacs")] + Emacs, + + #[serde(rename = "vim-normal")] + VimNormal, + + #[serde(rename = "vim-insert")] + VimInsert, + + #[serde(rename = "auto")] + Auto, +} + +impl KeymapMode { + pub fn as_str(&self) -> &'static str { + match self { + KeymapMode::Emacs => "EMACS", + KeymapMode::VimNormal => "VIMNORMAL", + KeymapMode::VimInsert => "VIMINSERT", + KeymapMode::Auto => "AUTO", + } + } +} + #[derive(Clone, Debug, Deserialize)] pub struct Stats { #[serde(default = "Stats::common_prefix_default")] @@ -201,7 +227,7 @@ pub struct Settings { pub max_preview_height: u16, pub show_help: bool, pub exit_mode: ExitMode, - pub vim: bool, + pub keymap_mode: KeymapMode, pub word_jump_mode: WordJumpMode, pub word_chars: String, pub scroll_context_lines: usize, @@ -437,7 +463,7 @@ impl Settings { // New users will get the new default, that is more similar to what they are used to. .set_default("enter_accept", false)? .set_default("sync.records", false)? - .set_default("vim", false)? + .set_default("keymap_mode", "emacs")? .add_source( Environment::with_prefix("atuin") .prefix_separator("_") -- cgit v1.3.1