我正在运行iterm2,当我在tmux模式下,我在vim中设置的配色方案不显示。只有我设定的配色方案。如果我从shell运行vim,配色方案显示正确-只有当我在tmux模式。

我尝试过在vim中设置:colorscheme molokai(见下面的截图),它没有改变-再次,iterm2的默认配色方案保持不变。

我是否遗漏了对iterm或tmux.conf的一些设置?我的图都在github上。


当前回答

在macOS Sierra 10.12.6下,在.tmux.conf中添加以下一行对我来说是有效的,

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

其他回答

我尝试了上面所有的解决方案,最后对我有用的是在.tmux.conf中放入以下几行:

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

在我的.tmux.conf中使用这两行对我来说是有效的,我使用的是带有Alacritty的Ubuntu 20.04。

set  -g default-terminal "tmux-256color"
set -ag terminal-overrides ",alacritty:RGB"

在一篇关于alacitty回购的文章中找到了它们,在YodaEmbedding提供的评论中:

https://github.com/alacritty/alacritty/issues/109

正如上面提到的@romainl,我需要通过添加-2标志来强制tmux使用256种颜色:

$ tmux -2

我添加了别名tmux='tmux -2'到我的bash_profile,所以,我不会忘记:)

我使用gnome终端,这解决了问题,但(0)不要忘记:

killall tmux

(1)编辑.tmux.conf

# 24 bit color
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"

(2)编辑:.vimrc

" Enable true color
if exists('+termguicolors')
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  set termguicolors
endif

rinetd发布的关于tmux回购问题的解决方案: https://github.com/tmux/tmux/issues/1246

如果你发现自己的处境和我一样,那上面的方法都没用。试试这个:

在.tmux.conf:

set -g default-terminal "xterm"

在bash配置中(可能是.bashrc或.bash_profile):

alias tmux="tmux -2"

然后运行:

killall tmux

然后重新启动tmux