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

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

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


当前回答

在我的.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,所以,我不会忘记:)

在我的.tmux.conf中,我并没有尝试导出一个不同的TERM或设置默认终端。

我在tmux中修复vim颜色的解决方案是在.tmux.conf中添加这一行:

set -g terminal-overrides 'xterm:colors=88'

我不确定为什么需要这种重写,因为我的TERM=xterm,我也将iTerm设置为xterm,但它似乎是有效的。

这有点过时,但值得一提的是,使用screen通常会破坏Home和End键。使用

export TERM="xterm-256color"

它应该保持这些功能,并允许配色方案(或电力线)工作良好。

我使用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

ENV:

Fedora 29工作站x86_64, GNOME终端3.30.1

VIM - Vi IMproven 8.1 (2018 年 5 月 18 日,编译于 Mar 8 2019 09:25:44)

GNU bash, version 4.4.23(1)-release (x86_64- rehat -linux- GNU)

tmux 2.7

Vim使用的是太阳能方案。

. vimrc

...
let g:solarized_termcolors=256
let g:solarized_termtrans=1

syntax enable
set background=dark
colorscheme solarized
...

bash中$TERM的值是:

[u@loc ~]$ echo $TERM
xterm-256color
[u@loc ~]$ tput colors
256

方法一:有效。

检查tmux会话中的$TERM值。得到

[u@loc ~]$ echo $TERM
screen
[u@loc ~]$ tput colors
8

因此,只需在tmux会话中设置export TERM=screen-256color。此方法仅在会话的当前窗格中有效。


方法二:有效。

创建~/.tmux.conf文件,并在文件中添加set -g default-terminal "tmux-256color"。

或者直接执行echo "set -g default-terminal \"tmux-256color\"" > ~/.tmux.conf "

然后关闭所有tmux会话。

启动一个新会话并检查tmux会话中的$TERM值。得到

[u@loc ~]$ echo $TERM
tmux-256color
[u@loc ~]$ tput colors
256

而且vim彩色方案适用于所有窗格和所有tmux会话。

我还尝试了~/.tmux.conf中的xterm-256color和screen-256color。它们都可以很好地为vim方案上色。

顺便说一下,我的~/中没有任何与此设置相关的配置。bash_profile、~ /。Bashrc和~/.vimrc。

参见https://github.com/tmux/tmux/wiki/FAQ#how-do-i-use-a-256-colour-terminal, https://github.com/tmux/tmux/wiki/FAQ#why-do-you-use-the-screen-terminal-description-inside-tmux

其他有用的演讲包括tmux# 699中的Vim配色方案更改、256-color-support-for-vim-background-in-tmux、get -256-colors-to-work- tmux、tmux-term-and-256- colors- support