Vim 在 tmux 中显示不正确的颜色

Vim displaying incorrect colors inside tmux

我有 Ubuntu 17.04,Tmux:2.3,vim:8.0,以及一个名为 onedark

的配色方案

Vim 当我 不在 内时显示正确的配色方案,但当我在 TMUX 时,vim 看起来完全不同。

我在 .bashrc、.vimrc 和 .tmux.conf 中尝试了所有可能的配置,但没有成功。 我最近才发现,当我 运行 vim 在 Tmux 中使用 sudo,root(管理)权限时,一切都按预期工作,我认为这不是一个好的解决方案。

所以我的问题是如何让 vim 显示一致的配色方案,而不管我在 Tmux 内部或外部的 root 权限或天气。

我与颜色相关的配置是。

.tmux.conf

set-option -sa terminal-overrides ",xterm*:Tc"
set -g default-terminal "xterm-256color"

.vimrc

set encoding=utf-8
set nocompatible 
set t_Co=256
set t_ut=
set background=dark
set showmatch
syntax on

if (empty($TMUX))

  if (has("nvim"))
    let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  endif

  if (has("termguicolors"))
    set termguicolors
  endif

endif

colorscheme one

如果在 tmux 内部或外部执行 echo $TERM,我得到 xterm-256color

罪魁祸首是 termguicolors 设置,您在终端而不是 Tmux 中启用了该设置。将其移出最外层 if 应该可以解决问题。