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

3G-Modding your eee 1000he hackintosh

As some of you may know I’ve been using snow leopard on my eee 1000he for quite a while(You can still get the modded DSDT I use on my system from my github page)

Read More: 3G-Modding your eee 1000he hackintosh

Finally migrated to jekyll

I’ve finally jumped the bandwagon and migrated my blog to jekyll, takes a little to get used to, but I can’t say I regret it.

Read More: Finally migrated to jekyll

Better tab completion for scp file names

As a lot of you may know, zsh offers tab completion for scp: filenames.
Normally it would connect and then list the files. As you can imagine this isn’t really that efficient.
The solution is quite simple… By adding

Read More: Better tab completion for scp file names