Zsh: Change cursor colour to indicate vi-mode
From Arch Forums.
It’s possible to change the cursor in urxvt when using zsh to indicate the current vi mode (e.g. grey for INSERT, red for NORMAL).
Append the following to ~/.zshrc
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # change cursor colour depending on vi mode zle-keymap-select () { if [ "$TERM" = "rxvt-unicode-256color" ]; then if [ $KEYMAP = vicmd ]; then echo -ne "\033]12;red\007" else echo -ne "\033]12;grey\007" fi fi }; zle -N zle-keymap-select zle-line-init () { zle -K viins echo -ne "\033]12;grey\007" }; zle -N zle-line-init |
Zsh auto-detects and sets the editing mode (default: emacs) to vi if $EDITOR=vim. If this environment variable isn’t set, or is set to something else, you’ll also need to add bindkey -v to your ~/.zshrc.


This works for me, but when used in tmux, it prints a weird charater to the screen and on some computers produces a beep. Any idea why this might be?
Changing
$TERM = “rxvt-unicode-256color”
to
$TERM != “linux”
should work for running tmux inside of xterm (I couldn’t get it to work in rvxt)