From a5727c135b5892c35f3bb95e6dd15a9a993ee0a1 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 30 Dec 2023 21:21:08 +0100 Subject: [PATCH] zsh: Change cursor shape for vi modes --- terminal/.config/zsh/.zshrc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/terminal/.config/zsh/.zshrc b/terminal/.config/zsh/.zshrc index 30a0a4c..f4156a8 100644 --- a/terminal/.config/zsh/.zshrc +++ b/terminal/.config/zsh/.zshrc @@ -151,6 +151,26 @@ bindkey "^[." insert-last-word bindkey -v # remove the delay for switching modes export KEYTIMEOUT=1 +# Change cursor shape for different vi modes. +function zle-keymap-select { + if [[ ${KEYMAP} == vicmd ]] || + [[ $1 = 'block' ]]; then + echo -ne '\e[2 q' + + elif [[ ${KEYMAP} == main ]] || + [[ ${KEYMAP} == viins ]] || + [[ ${KEYMAP} = '' ]] || + [[ $1 = 'beam' ]]; then + echo -ne '\e[6 q' + fi +} +zle -N zle-keymap-select +# Use beam shape cursor on startup. +_fix_cursor() { + echo -ne '\e[6 q' +} +precmd_functions+=(_fix_cursor) + # space puts a space, even in cmd mode bindkey -a ' ' magic-space # always allow backspace/delete to remove letters