From 4098771120137e926af55af873f077e142a8fb35 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Sat, 26 Jul 2025 11:32:26 +0200 Subject: [PATCH] Add vim mode indicators and enhanced keybindings to zsh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Enable vim keybindings with defaultKeymap = "viins" - Add cursor shape changes: line cursor for insert mode, block for normal mode - Reduce mode switching delay from 400ms to 10ms for faster response - Add vim-style history navigation with k/j in normal mode - Add history search with / and ? in normal mode - Add word movement with Ctrl+arrow keys in insert mode - Integrate with Powerlevel10k prompt symbols for mode indication Provides clear visual feedback for vim mode changes with multiple indicators. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- zsh.nix | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/zsh.nix b/zsh.nix index a550336..915ab6e 100644 --- a/zsh.nix +++ b/zsh.nix @@ -3,6 +3,7 @@ { programs.zsh = { enable = true; + defaultKeymap = "viins"; enableVteIntegration = true; enableCompletion = true; autosuggestion.enable = true; @@ -41,6 +42,40 @@ # Load Powerlevel10k configuration (managed by Nix) source ~/.p10k.zsh + + # Vim mode configuration + # Reduce delay when switching modes (10ms instead of 400ms) + export KEYTIMEOUT=1 + + # Cursor shape changes for vim modes + function zle-keymap-select { + case $KEYMAP in + vicmd) echo -ne '\e[1 q';; # block cursor for normal mode + viins|main) echo -ne '\e[5 q';; # line cursor for insert mode + esac + } + zle -N zle-keymap-select + + # Ensure we start with line cursor in insert mode + function zle-line-init { + echo -ne '\e[5 q' + } + zle -N zle-line-init + + # Fix cursor after each command + function preexec { + echo -ne '\e[5 q' + } + + # Additional vim-like bindings + bindkey -M vicmd 'k' history-search-backward + bindkey -M vicmd 'j' history-search-forward + bindkey -M vicmd '/' history-incremental-search-backward + bindkey -M vicmd '?' history-incremental-search-forward + + # Better word movement in insert mode + bindkey '^[[1;5C' forward-word # Ctrl+Right + bindkey '^[[1;5D' backward-word # Ctrl+Left ''; };