Integrating tmux, Zsh, Vim, and iTerm2

tmux italics and vim colors

Confirm that iTerm is set to xterm-256color in the application preferences.

Set color interpretation in Zsh. This affects italics rendering in tmux.

export TERM="screen-256color"

tmux needs to be set to screen-256color to display vim colors properly. tmux configs belong in ~/.tmux.conf.

set -g default-terminal "screen-256color"

You can confim that terminal colors are set correctly by running:

echo $TERM

Regular sessions should print xterm-256color and tmux sessions should print screen-256color.

Vim mode in Zsh

In zshrc:

# Enable vi mode
bindkey -v

# Visual feedback
#
# Note there are several ways to tell zsh
# to run this hook function before each prompt
precmd() { RPROMPT="" }

# Zsh line editor for feedback via custom widget
# to show keymap when not in "insert" mode
function zle-line-init zle-keymap-select {
   RPS1="${${KEYMAP}/(main|viins)/}" # Param expansion
   zle reset-prompt
}

zle -N zle-line-init
zle -N zle-keymap-select

Vim mode in tmux

In tmux.conf:

# Enable vim mode
set -g mode-keys vi

# Shorten escape sequence time
set -g escape-time 50

Update external changes to open buffer

Manually

run :checktime

Automatically

In vimrc add:

set autoread
" and
au CursorHold,CursorHoldI * checktime " Trigger when cursor stops moving
" or
au FocusGained,BufEnter * checktime " Trigger on terminal focus or buffer change

To have FocusGained work in vim inside tmux, install the plugin: vim-tmux-focus-events.

Resources