在使用 Solarized 的 iTerm2 中,vim 的颜色不正确
我在终端 vim(非 GUI)和日光配色方案中遇到了 iTerm2 的奇怪问题。首先,我将 iTerm2 设置为使用深色日晒配色方案。
我也在 vim 中使用 Solarized。我的 .vimrc 中有以下几行在
set background=dark
colorscheme solarized
终端中,配色方案看起来不正确:
作为参考,这是它在 MacVim (gui vim) 下的样子
我需要在 iTerm 或 .vimrc 中进行哪些更改才能使颜色在我的控制台 vim 中正确显示?
I am having a strange issue with iTerm2, in terminal vim (non-gui) and the solarized color scheme. First, I have set iTerm2 to use the dark solarized colour scheme.
I am also using solarized for vim. I have the following lines in my .vimrc
set background=dark
colorscheme solarized
In the terminal the color scheme looks incorrect:
For reference this is how it looks under MacVim (gui vim)
What do I need to change in iTerm or my .vimrc to get the colors looking correctly in my console vim?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
有几件事需要检查:
在 iTerm2 中,在“首选项”中 ->个人资料 ->终端,在“终端仿真”下,将“报告终端类型:”设置为 xterm-256color。
在您的 .vimrc 中,您还可以设置一些选项以确保它使用 256 种颜色:
其中之一应该可以工作,但首先是 #1。
但是,如果您使用的是 Snow Leopard 上默认内置的 vim,它将无法工作,因为它不支持 256 色。我相信 Lion 中的内置版本可以。
编辑:根据对此答案的一些评论,我从上面的
.vimrc
示例中删除了let g:solarized_termcolors = 256
行。看来这对某些人来说可能是个问题。另一位说添加行let g:solarized_termcolors = 16
修复了颜色显示问题。您自己的里程可能会有所不同。第二次编辑:如果您已将 Solarized 调色板加载到 iTerm2 中,则必须
let g:solarized_termcolors=16
。仅当您不使用 Solarized 调色板作为 iTerm2 颜色预设时才使用 g:solarized_termcolors=256。A couple of things to check:
In iTerm2, in Preferences -> Profiles -> Terminal, under "Terminal Emulation" you have "Report Terminal Type:" set to xterm-256color.
In your .vimrc, there are some options you can also set to make sure it's using 256 colors:
And one of those should work, but #1 first.
BUT, if you're using the default, built in vim on Snow Leopard, it won't work, as it's not built with support for 256 colors. I believe the built in version in Lion does.
Edit: Based on several comments on this answer, I've removed
let g:solarized_termcolors = 256
line from the.vimrc
example above. It appears that could be a problem for some. Another says that adding the linelet g:solarized_termcolors = 16
fixed a color display problem. Your own mileage may vary.Second Edit: If you've loaded the solarized color palette into iTerm2, then you must
let g:solarized_termcolors=16
. Onlylet g:solarized_termcolors=256
if you are not using the solarized palette as your iTerm2 color preset.上面的答案对我不起作用。
我在 OS X 10.7.4 上使用 iTerm2 和 vim 7.3。
如果上述解决方案也不适合您,请尝试此
更新:根据 Jim Stewart 的说法,这也适用于 Kitty。
The above answers didn't work for me.
I'm using iTerm2 with vim 7.3 on OS X 10.7.4.
If the above solutions didn't work for you too, try this
Update: According to Jim Stewart, this works on Kitty too.
https://github.com/altercation/solarized/tree/master/iterm2 -colors-solarized
下载 Solarized 包 (https://github.com/altercation/solarized)并按照说明进行操作:
======================================
或者:
修改 .vimrc
深色主题:
光
https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized
Download Solarized package (https://github.com/altercation/solarized) and follow instructions:
====================================
Or:
Modify .vimrc
Dark Theme:
Light
这对我在 OS X 10.9.1 的 iTerm 2 以及终端中有效。我犯的一个错误是将 colorcheme 声明放在 termtrans 和 termcolors 设置之前(我需要这两个设置才能使其工作)。正如其他人所说,我将终端类型设置为 xterm-256color
This worked for me in OS X 10.9.1 in iTerm 2 as well as Terminal. One mistake I was making was putting the colorscheme declaration before the termtrans and termcolors settings (and I needed both of these to make it work). As others have said, I set my terminal type to xterm-256color
来自创建者:http://ethanschoonover.com/solarized/vim-colors-solarized
let g:solarized_termcolors=256
From the creator: http://ethanschoonover.com/solarized/vim-colors-solarized
let g:solarized_termcolors=256
我在 OSX 10.11.6、iTerm2 Build 3.0.12 上遇到了同样的问题。
这是我的修复方法。
.vimrc
语法启用
设置背景=深色
colorcheme Solarized
将报告终端类型设置为
xterm-256color
。I struggled with the same problem on OSX 10.11.6, iTerm2 Build 3.0.12.
Here is my fix for it.
.vimrc
syntax enable
set background=dark
colorscheme solarized
Set Report Terminal Type to
xterm-256color
.Bill Turner 的答案有效,但有一种方法可以使颜色与 MacVim 完全匹配。 Solarized 专门支持 iTerm2 以及其他终端仿真器。
colorscheme Solarized
这应该将 vim 颜色设置为iTerm2 与 GUI 编辑器中的完全相同。
Bill Turner's answer works, but there is a way to get the colors to match MacVim exactly. Solarized has support specifically for iTerm2, among other terminal emulators.
colorscheme solarized
This should set the vim colors in iTerm2 to be exactly as they are in gui editors.
解决这个问题的一个简单方法是:
在 vim-color-solarized 的颜色目录中存在一个名为 'solarozed.vim' 的档案
打开此文件并搜索:
exe "let s:bg_back = ' ".s:vmode."bg=".s:back ."'"
替换为:
exe "让 s:bg_back = ' ".s:vmode."bg=".s:none ."'"
A simple way to solve this problem is:
In colors dir on vim-color-solarized exist an arquive named 'solarozed.vim'
Open this file and search:
exe "let s:bg_back = ' ".s:vmode."bg=".s:back ."'"
replace to:
exe "let s:bg_back = ' ".s:vmode."bg=".s:none ."'"
对于像我一样仍然遇到问题的人,我安装了 iterm2 solarized 颜色配置文件。将 vim-color-solarized 安装到 vim 包并按照说明进行操作是不必要的并且不兼容。有一些有趣的突出显示问题,如上面的屏幕截图所示。
经验教训:不要两者都做。
For any still having issues like I was, I had installed iterm2 solarized color profile. Installing vim-color-solarized to vim bundles and following the instructions was unnecessary and was incompatible. There were funny highlighting issues like in the screen capture above.
Lesson learned: don't do both.
我尝试了之前的所有建议。我刚刚将
set t_Co=256
添加到 .vimrc 并且它已修复。我不需要创建 tmux 别名或更改我的配置文件。I tried all of the previous suggestions. I just added
set t_Co=256
to .vimrc and it was fixed. I didn't need to create atmux
alias or change my config file.以前的答案都不适合我。显然我失踪了:
None of the previous answers worked for me. Apparently I was missing: