- 設定 vim 支援 256 色
- 設定終端機 支援 256 色
- 設定 tmux 支援 256 色
設定 tmux 支援 256 色
tmux.conf
set -g default-terminal "screen-256color"
.zshrc, .bashrc
# You want $TERM to be screen-256color when tmux is running, and you want it to be xterm-256color when tmux is not running.
if [ "$TERM" = "screen" ] && [ -n "$TMUX" ]; then
export TERM=screen-256color
else
export TERM=xterm-256color
fi
tmux 對於 256 色的支援
$ set -g default-terminal "screen-256color"
使得 tmux 以 TERM=screen-256color 建立一個新的 shell 時
如果你的 rc file 又重新定義
$ export TERM=xterm-256colorvim 執行時 tmux 會用到錯誤的 TERM
Reference
256 color support for vim background in tmux
Vim: Difference between t_Co=256 and term=xterm-256color in conjunction with TMUX
Zsh, Tmux, Vim, and 256 Color Madness
So… if you can configure each individual part: terminal emulator: xterm-256color tmux/screen: screen-256color vim: nothing and you are done.
tmux, TERM and 256 colours support
[Tmux - ArchWiki] Correct the TERM variable according to terminal type
~/.tmux.conf
## set the default TERM
set -g default-terminal screen
## update the TERM variable of terminal emulator when creating a new session or attaching a existing session
set -g update-environment 'DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY TERM'
## determine if we should enable 256-colour support
if "[[ ${TERM} =~ 256color || ${TERM} == fbterm ]]" 'set -g default-terminal screen-256color'
## workaround for handling TERM variable in multiple tmux sessions properly from http://sourceforge.net/p/tmux/mailman/message/32751663/ by Nicholas Marriott
if [[ -n ${TMUX} && -n ${commands[tmux]} ]];then
case $(tmux showenv TERM 2>/dev/null) in
*256color) ;&
TERM=fbterm)
TERM=screen-256color ;;
*)
TERM=screen
esac
fi