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

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

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


当前回答

I just discovered why I was having a lot of confusion. I, like others here, was having a difficult time getting the default-terminal setting to take effect. I remembered that I had a tmux session in the background. I re-attached my session, closed out my processes, and closed ALL tmux processes. The next time I restarted tmux the default-terminal setting in .tmux.conf began to take effect. I don't know if others are doing this as well but I recommend closing all tmux processes before modifying the .tmux.conf file.

我让我的设置在我的本地机器上工作(OSX 10.9.5 with iTerm2),没有对.bashrc或.bash_profile进行任何修改。我所做的只是将行set -g default-terminal "xterm-256color"添加到~/.tmux.conf并重新启动所有tmux进程。

我让我的远程设置(ssh到Ubuntu 14.04)以完全相同的方式工作,而不需要对.bashrc进行任何修改。我只是在远程机器上的~/.tmux.conf中添加了set -g default-terminal "xterm-256color",并重新启动了所有远程tmux进程。

你可以在tmux会话中通过echo $TERM来测试Vim所看到的内容。它一直将screen作为值,直到我重新启动所有tmux进程,此时它如预期的那样反射xterm-256color。

希望这能有所帮助。

其他回答

I just discovered why I was having a lot of confusion. I, like others here, was having a difficult time getting the default-terminal setting to take effect. I remembered that I had a tmux session in the background. I re-attached my session, closed out my processes, and closed ALL tmux processes. The next time I restarted tmux the default-terminal setting in .tmux.conf began to take effect. I don't know if others are doing this as well but I recommend closing all tmux processes before modifying the .tmux.conf file.

我让我的设置在我的本地机器上工作(OSX 10.9.5 with iTerm2),没有对.bashrc或.bash_profile进行任何修改。我所做的只是将行set -g default-terminal "xterm-256color"添加到~/.tmux.conf并重新启动所有tmux进程。

我让我的远程设置(ssh到Ubuntu 14.04)以完全相同的方式工作,而不需要对.bashrc进行任何修改。我只是在远程机器上的~/.tmux.conf中添加了set -g default-terminal "xterm-256color",并重新启动了所有远程tmux进程。

你可以在tmux会话中通过echo $TERM来测试Vim所看到的内容。它一直将screen作为值,直到我重新启动所有tmux进程,此时它如预期的那样反射xterm-256color。

希望这能有所帮助。

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

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

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

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

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

从tmux手册页,添加标志如下:

tmux -2

这个-2标志强制tmux以256色模式运行。

这对我很有用

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

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