Add cursor shape change dependant on vi mode
This commit is contained in:
36
zshrc
36
zshrc
@@ -66,6 +66,42 @@ autoload -U edit-command-line
|
||||
zle -N edit-command-line
|
||||
bindkey -M vicmd '^V' edit-command-line
|
||||
|
||||
# Enable changing cursor shape based on vi mode
|
||||
if [ "$TMUX" != "" ]; then
|
||||
tmux_before="\EPtmux;\E"
|
||||
tmux_after="\E\\"
|
||||
fi
|
||||
if [ "$ITERM_SESSION_ID" != "" ]; then
|
||||
# iterm2 cursor shape escape sequences
|
||||
cursor_block="$tmux_before\E]50;CursorShape=0\C-G$tmux_after"
|
||||
cursor_line="$tmux_before\E]50;CursorShape=1\C-G$tmux_after"
|
||||
else
|
||||
# VTE compatible cursor shape escape sequences
|
||||
cursor_block="$tmux_before\E[2 q$tmux_after"
|
||||
cursor_line="$tmux_before\E[6 q$tmux_after"
|
||||
fi
|
||||
unset tmux_before tmux_after
|
||||
|
||||
if [[ ! -z "$cursor_block" && ! -z "$cursor_line" ]]; then
|
||||
# Change cursor shape when vi mode changes
|
||||
function zle-keymap-select zle-line-init {
|
||||
case $KEYMAP in
|
||||
vicmd) print -n -- "$cursor_block" ;;
|
||||
viins|main) print -n -- "$cursor_line" ;;
|
||||
esac
|
||||
zle reset-prompt
|
||||
zle -R
|
||||
}
|
||||
|
||||
# Change cursor shape when line editing is finished
|
||||
function zle-line-finish { print -n -- "$cursor_block" }
|
||||
|
||||
# Register cursor shape hooks
|
||||
zle -N zle-keymap-select
|
||||
zle -N zle-line-init
|
||||
zle -N zle-line-finish
|
||||
fi
|
||||
|
||||
# Remove duplicates from environment variables
|
||||
typeset -U PATH
|
||||
typeset -U MANPATH
|
||||
|
||||
Reference in New Issue
Block a user