我正在运行iterm2,当我在tmux模式下,我在vim中设置的配色方案不显示。只有我设定的配色方案。如果我从shell运行vim,配色方案显示正确-只有当我在tmux模式。
我尝试过在vim中设置:colorscheme molokai(见下面的截图),它没有改变-再次,iterm2的默认配色方案保持不变。
我是否遗漏了对iterm或tmux.conf的一些设置?我的图都在github上。
我正在运行iterm2,当我在tmux模式下,我在vim中设置的配色方案不显示。只有我设定的配色方案。如果我从shell运行vim,配色方案显示正确-只有当我在tmux模式。
我尝试过在vim中设置:colorscheme molokai(见下面的截图),它没有改变-再次,iterm2的默认配色方案保持不变。
我是否遗漏了对iterm或tmux.conf的一些设置?我的图都在github上。
当前回答
我尝试了上面所有的解决方案,最后对我有用的是在.tmux.conf中放入以下几行:
set -g default-terminal "xterm-256color"
其他回答
正如上面提到的@romainl,我需要通过添加-2标志来强制tmux使用256种颜色:
$ tmux -2
我添加了别名tmux='tmux -2'到我的bash_profile,所以,我不会忘记:)
我需要vim在ubuntu的终端上使用tmux正确显示,在windows上使用cygwin/mintty。我把答案像这样组合起来。
打印.bashrc:
alias tmux="tmux -2"
在. 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
基于这个问题的答案,这个Vim wiki页面和这个块游标问题
我也有同样的问题。唯一不同的是我使用的是太阳能而不是莫洛凯。
为了解决这个问题,我在~/.bashrc中设置了一个别名:
alias tmux="TERM=screen-256color-bce tmux"
在~/.tmux.conf中设置default-terminal选项:
set -g default-terminal "xterm"
最后,执行$ source ~/。Bashrc加载新别名。
如果你使用tmuxinator或mux,你需要在.bashrc或.zshrc中添加这些:
alias tmux='TERM=screen-256color tmux -2'
alias tmuxinator='TERM=screen-256color tmuxinator'
alias mux='TERM=screen-256color mux'
这些力用256色在终端上。
然后tmux, tmuxinator和mux命令都将工作。
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