Changing the cursor color within tmux based on vi mode

  • September 18, 2011
Table of Contents

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.

comments powered by Disqus

Related Posts

Precompiled qgit.app 2.2 for Mac

So I was looking for a git visualizer the other day… GitNub looks nifty but doesn’t quite cut it and gitk is just plain ugly.

Read More

gentoo osx

Update: I also forgot to run the emerge -u world after the bootstrap. So you might want to do that yourself.

Read More

UTF-8 and bom problems in php

So I was trying to debug on of our Sites because we we were having an odd sign at the beginning of the files.

Read More