Changing the cursor color within tmux based on vi mode

As outlined on SE and SU you can execute actions in zsh when you change between normal and insert mode in a vi mode zsh session.

For changing the cursor color see the snippet below.

# use cursor as indicator of vi mode
zle-keymap-select () {
  if [ $KEYMAP = vicmd ]; then
    if [[ $TMUX = '' ]]; then
      echo -ne "\033]12;Red\007"
    else
      printf '\033Ptmux;\033\033]12;red\007\033\\'
    fi
  else
    if [[ $TMUX = '' ]]; then
      echo -ne "\033]12;Grey\007"
    else
      printf '\033Ptmux;\033\033]12;grey\007\033\\'
    fi
  fi
}
zle-line-init () {
  zle -K viins
  echo -ne "\033]12;Grey\007"
}
zle -N zle-keymap-select
zle -N zle-line-init

Put it somewhere in your zshrc and your cursor should switch to red when you enter normal mode and become grey again when you leave it.

blog comments powered by Disqus
 Scroll to top