macos 在 tmux 模式下丢失 vim 颜色方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10158508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
lose vim colorscheme in tmux mode
提问by tristen
I'm running iterm2 and when I'm in tmux mode the colorscheme I have set in vim does not show up. Only the color scheme I've set in iterm. If I run vim from shell the colorscheme appears correct - its only when I'm in tmux mode.
我正在运行 iterm2,当我处于 tmux 模式时,我在 vim 中设置的颜色方案没有显示出来。只有我在 iterm 中设置的配色方案。如果我从 shell 运行 vim,颜色方案看起来是正确的 - 只有当我处于 tmux 模式时。
I've tried setting :colorscheme molokai
when in vim (see screenshot below) and it doesn't change - again, the default colorscheme for iterm2 remains.
我试过:colorscheme molokai
在 vim 中进行设置(见下面的截图)并且它没有改变 - 同样,iterm2 的默认颜色方案仍然存在。
Am I missing some setting to iterm or tmux.conf? My dotfles are up on github here.
我是否缺少 iterm 或 tmux.conf 的一些设置?我的 dotfles 在 github 上。
回答by Seyeong Jeong
I had the same problem. Only difference was I am using solarize
rather then molokai
.
我有同样的问题。唯一的区别是我使用的是solarize
而不是molokai
.
To fix the issue, I have set up an alias in ~/.bashrc
:
为了解决这个问题,我在以下位置设置了一个别名~/.bashrc
:
alias tmux="TERM=screen-256color-bce tmux"
And set up the default-terminal
option in ~/.tmux.conf
:
并default-terminal
在~/.tmux.conf
以下位置设置选项:
set -g default-terminal "xterm"
Lastly, do $ source ~/.bashrc
to load new alias.
最后,$ source ~/.bashrc
加载新别名。
回答by tristen
As @romainl mentions above, I needed to force tmux to use 256 colors by adding the -2
flag:
正如@romainl 上面提到的,我需要通过添加-2
标志来强制 tmux 使用 256 种颜色:
$ tmux -2
I added alias tmux='tmux -2'
to my bash_profile, so, I don't forget :)
我添加alias tmux='tmux -2'
到我的 bash_profile,所以,我不会忘记 :)
回答by ElefEnt
I tried all the solutions above and what finally worked for me is putting the following lines in .tmux.conf
:
我尝试了上述所有解决方案,最终对我有用的是将以下几行放入.tmux.conf
:
set -g default-terminal "xterm-256color"
回答by Chev
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.
我刚刚发现为什么我有很多困惑。我和这里的其他人一样,很难让默认终端设置生效。我记得我在后台有一个 tmux 会话。我重新附加了我的会话,关闭了我的进程,并关闭了所有 tmux 进程。下次我重新启动 tmux 时,默认终端设置.tmux.conf
开始生效。我不知道其他人是否也这样做,但我建议在修改.tmux.conf
文件之前关闭所有 tmux 进程。
I got my setup to work on my local machine (OSX 10.9.5 with iTerm2) without any modification to .bashrc
or .bash_profile
. All I did was add the line set -g default-terminal "xterm-256color"
to ~/.tmux.conf
and restarted all tmux processes.
我让我的设置在我的本地机器上工作(带有 iTerm2 的 OSX 10.9.5),而没有对.bashrc
或进行任何修改.bash_profile
。我所做的只是将行添加set -g default-terminal "xterm-256color"
到~/.tmux.conf
并重新启动所有TMUX过程。
I got my remote setup (ssh to Ubuntu 14.04) to work exactly the same way without any modifications to .bashrc
. I simply added set -g default-terminal "xterm-256color"
to ~/.tmux.conf
on my remote machine and restarted all remote tmux processes.
我让我的远程设置(ssh 到 Ubuntu 14.04)以完全相同的方式工作,无需对.bashrc
. 我只是在我的远程机器上添加set -g default-terminal "xterm-256color"
到~/.tmux.conf
并重新启动所有远程 tmux 进程。
You can test what Vim is seeing by doing echo $TERM
from within a tmux session. It kept saying screen
as the value until I restarted all tmux processes, at which point it reflected xterm-256color
as expected.
您可以通过echo $TERM
在 tmux 会话中执行操作来测试 Vim 看到的内容。它一直说screen
这个值,直到我重新启动所有 tmux 进程,此时它xterm-256color
按预期反映。
Hope that helps.
希望有帮助。
回答by Jpatrick
So this a bit on the stale side, but it's might be worth mentioning that using screen will often break the Home and End keys. Using
所以这有点陈旧,但值得一提的是,使用 screen 通常会破坏 Home 和 End 键。使用
export TERM="xterm-256color"
in should keep the functionality of these and allow the color scheme (or powerline) to work fine.
in 应该保持这些功能并允许配色方案(或电力线)正常工作。
回答by Andrew Johnston
I needed vim to display correctly with tmux in terminal on ubuntu and cygwin/mintty on windows. I got it to work by combining the answers like this.
我需要 vim 在 ubuntu 上的终端和 cygwin/mintty 在 windows 上使用 tmux 正确显示。我通过结合这样的答案让它工作。
In .bashrc:
在 .bashrc 中:
alias tmux="tmux -2"
In .vimrc:
在 .vimrc 中:
" use 256 colors in terminal
if !has("gui_running")
set t_Co=256
set term=screen-256color
endif
" fix cursor display in cygwin
if has("win32unix")
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
endif
based on answers from this question, this Vim wiki pageand this block cursor question
基于这个问题的答案,这个 Vim wiki 页面和这个块光标问题
回答by Lion Lai
I have tried all of the instructions above, and I found out the most important thing is I have to explicitly add the following line in my .bashrc file.
我已经尝试了上面的所有说明,我发现最重要的是我必须在我的 .bashrc 文件中明确添加以下行。
export TERM=screen-256color
I don't know why alias tmux="TERM=screen-256color-bce tmux" doesn't work out. I use Sierra 10.12.1.
我不知道为什么 alias tmux="TERM=screen-256color-bce tmux" 不起作用。我使用 Sierra 10.12.1。
回答by Yanzhe Chen
In case anyone needs 24-bit color support:
如果有人需要 24 位颜色支持:
Tmux supports 24-bit color as of version 2.2. If your terminal supports 24-bit color, add your terminal to the terminal-overrides setting. For example,
从版本 2.2 开始,Tmux 支持 24 位颜色。如果您的终端支持 24 位颜色,请将您的终端添加到终端覆盖设置中。例如,
set -ga terminal-overrides ",xterm-256color:Tc"
My environment checklist:
我的环境清单:
- macOS Sierra 10.12.3
- iTerm2 3.0.14 (Report Terminal Type is
xterm-256color
) - neovim 0.1.7 (Enable 24-bit color by adding:
xterm-256color
to.vimrc
) - tmux 2.3 (Add
set -ga terminal-overrides ",xterm-256color:Tc"
to.tmux.conf
)
- macOS Sierra 10.12.3
- iTerm2 3.0.14 (报表终端类型为
xterm-256color
) - neovim 0.1.7(通过添加启用 24 位颜色:
xterm-256color
to.vimrc
) - tmux 2.3(添加
set -ga terminal-overrides ",xterm-256color:Tc"
到.tmux.conf
)
Nothing else I need to add in .bashrc
or .zshrc
.
我不需要添加任何其他内容.bashrc
或.zshrc
。
Hope this could help.
希望这会有所帮助。
回答by HK_
Since this is the first result on Google and since none of the above helped..wanted to post this so that someone might find it helpful
由于这是谷歌上的第一个结果,而且由于以上都没有帮助......想发布这个以便有人可能会发现它有帮助
in .vimrc
:
在.vimrc
:
set background=dark
set t_Co=256
HTH
HTH
回答by Zack Zhu
Adding the following line in .tmux.conf worked for me with macOS Sierra 10.12.6,
在 .tmux.conf 中添加以下行适用于 macOS Sierra 10.12.6,
set -g default-terminal "screen-256color"
set -g 默认终端“screen-256color”