macos 使用 Solarized 在 iTerm2 中使用 vim 的颜色不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7278267/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:22:55  来源:igfitidea点击:

Incorrect colors with vim in iTerm2 using Solarized

macosvimcolor-schemeiterm

提问by Zameer Manji

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.

我在终端 vim(非 gui)和日光化配色方案中遇到了 iTerm2 的一个奇怪问题。首先,我已将 iTerm2 设置为使用深色日光化配色方案。

I am also using solarized for vim. I have the following lines in my .vimrc

我也在 vim 中使用了solarized。我的 .vimrc 中有以下几行

set background=dark
colorscheme solarized

In the terminal the color scheme looks incorrect: console vim

在终端中,配色方案看起来不正确: 控制台 vim

For reference this is how it looks under MacVim (gui vim) gui vim

作为参考,这是它在 MacVim (gui vim) 下的样子 图形界面

What do I need to change in iTerm or my .vimrc to get the colors looking correctly in my console vim?

我需要在 iTerm 或我的 .vimrc 中更改什么才能使颜色在控制台 vim 中正确显示?

回答by Bill Turner

A couple of things to check:

需要检查的几件事:

  1. In iTerm2, in Preferences -> Profiles -> Terminal, under "Terminal Emulation" you have "Report Terminal Type:" set to xterm-256color.

  2. In your .vimrc, there are some options you can also set to make sure it's using 256 colors:

    set background=dark
    " solarized options 
    let g:solarized_visibility = "high"
    let g:solarized_contrast = "high"
    colorscheme solarized
    
    And one of those should work, but #1 first.

  1. 在 iTerm2 中,在首选项 -> 配置文件 -> 终端中,在“终端仿真”下,您将“报告终端类型:”设置为 xterm-256color。

  2. 在您的 .vimrc 中,您还可以设置一些选项以确保它使用 256 色:

    set background=dark
    " solarized options 
    let g:solarized_visibility = "high"
    let g:solarized_contrast = "high"
    colorscheme solarized
    
    其中一个应该可以工作,但首先要#1。

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.

但是,如果您在 Snow Leopard 上使用默认的内置 vim,它将无法工作,因为它不支持 256 色。我相信 Lion 中的内置版本确实如此。

Edit:Based on several comments on this answer, I've removed let g:solarized_termcolors = 256line from the .vimrcexample above. It appears that could be a problem for some. Another says that adding the line let g:solarized_termcolors = 16fixed a color display problem. Your own mileage may vary.

编辑:基于对这个答案的几条评论,我let g:solarized_termcolors = 256.vimrc上面的例子中删除了一行。对某些人来说,这似乎是个问题。另一个说添加该行let g:solarized_termcolors = 16修复了颜色显示问题。您自己的里程可能会有所不同。

Second Edit:If you've loaded the solarized color palette into iTerm2, then you must let g:solarized_termcolors=16. Only let g:solarized_termcolors=256if you are notusing the solarized palette as your iTerm2 color preset.

第二次编辑:如果您已将日晒调色板加载到 iTerm2 中,那么您必须let g:solarized_termcolors=16. 仅let g:solarized_termcolors=256当您使用日晒调色板作为 iTerm2 颜色预设时。

回答by Jason Yeo

The above answers didn't work for me.

以上答案对我不起作用。

I'm using iTerm2 with vim 7.3 on OS X 10.7.4.

我在 OS X 10.7.4 上使用 iTerm2 和 vim 7.3。

If the above solutions didn't work for you too, try this

如果上述解决方案对您也不起作用,请尝试此操作

syntax on
set background=dark
let g:solarized_termtrans = 1
colorscheme solarized

Update: According to Jim Stewart, this works on Kittytoo.

更新:根据 Jim Stewart 的说法,这也适用于Kitty

回答by d.danailov

https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized

https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized

Download Solarized package (https://github.com/altercation/solarized) and follow instructions:

下载 Solarized 包 ( https://github.com/altercation/solarized) 并按照说明进行操作:

Open iTerm 2, open Preferences, click on the "Profiles" (formerly Addresses, formerly Bookmarks) icon in the preferences toolbar, then select the "colors" tab. Click on the "load presets" and select "import...". Select the Solarized Light or Dark theme file.

You have now loaded the Solarized color presets into iTerm 2, but haven't yet applied them. To apply them, simply select an existing profile from the profile list window on the left, or create a new profile. Then select the Solarized Dark or Solarized Light preset from the "Load Presets" drop down.

打开iTerm 2,打开Preferences,点击首选项工具栏中的“Profiles”(以前的Addresses,以前的Bookmarks)图标,然后选择“colors”选项卡。单击“加载预设”并选择“导入...”。选择 Solarized Light 或 Dark 主题文件。

您现在已将 Solarized 颜色预设加载到 iTerm 2 中,但尚未应用它们。要应用它们,只需从左侧的配置文件列表窗口中选择一个现有的配置文件,或创建一个新的配置文件。然后从“加载预设”下拉列表中选择 Solarized Dark 或 Solarized Light 预设。

====================================

====================================

Or:

或者:

cd ~/.vim/bundle
git clone git://github.com/altercation/vim-colors-solarized.git

Modify .vimrc

修改 .vimrc

Dark Theme:

黑暗主题:

syntax enable
set background=dark
colorscheme solarized

Light

syntax enable
set background=light
colorscheme solarized

回答by Amar B

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

这在 iTerm 2 和终端的 OS X 10.9.1 中对我有用。我犯的一个错误是将 colorcheme 声明放在 termtrans 和 termcolors 设置之前(我需要这两个设置才能使其工作)。正如其他人所说,我将终端类型设置为 xterm-256color

if !has("gui_running")
    let g:solarized_termtrans=1
    let g:solarized_termcolors=256
endif

colorscheme solarized
set background=dark

回答by Jason Kim

I struggled with the same problem on OSX 10.11.6, iTerm2 Build 3.0.12.

我在 OSX 10.11.6、iTerm2 Build 3.0.12 上遇到了同样的问题。

Here is my fix for it.

这是我的修复方法。

  1. .vimrc

    syntax enable set background=dark colorscheme solarized

  2. Set Report Terminal Type to xterm-256color.

  1. .vimrc

    语法 enable set background=dark colourscheme solarized

  2. 将报告终端类型设置为xterm-256color

enter image description here

在此处输入图片说明

  1. Set color preset in the profile to Solarized Dark
  1. 将配置文件中的颜色预设设置为 Solarized Dark

enter image description here

在此处输入图片说明

回答by Proksima

From the creator: http://ethanschoonover.com/solarized/vim-colors-solarized

来自创作者:http: //ethanschoonover.com/solarized/vim-colors-solarized

IMPORTANT NOTE FOR TERMINAL USERS:

If you are going to use Solarized in Terminal mode (i.e. not in a GUI version like gvim or macvim), please please please consider setting your terminal emulator's colorscheme to used the Solarized palette. I've included palettes for some popular terminal emulator as well as Xdefaults in the official Solarized download available from Solarized homepage. If you use Solarized without these colors, Solarized will need to be told to degrade its colorscheme to a set compatible with the limited 256 terminal palette (whereas by using the terminal's 16 ansi color values, you can set the correct, specific values for the Solarized palette).

If you do use the custom terminal colors, solarized.vim should work out of the box for you. If you are using a terminal emulator that supports 256 colors and don't want to use the custom Solarized terminal colors, you will need to use the degraded 256 colorscheme. To do so, simply add the following line before the colorschem solarized line:

终端用户的重要提示:

如果您打算在终端模式下使用 Solarized(即不是像 gvim 或 macvim 这样的 GUI 版本),请考虑将您的终端模拟器的颜色方案设置为使用 Solarized 调色板。我已经在 Solarized 主页提供的官方 Solarized 下载中包含了一些流行的终端模拟器的调色板以及 Xdefaults。如果您在没有这些颜色的情况下使用 Solarized,则需要告知 Solarized 将其配色方案降级为与有限的 256 终端调色板兼容的集合(而通过使用终端的 16 个 ansi 颜色值,您可以为 Solarized 设置正确的特定值调色板)。

如果您确实使用自定义终端颜色,solarized.vim 应该为您开箱即用。如果您使用的是支持 256 色的终端仿真器并且不想使用自定义的 Solarized 终端颜色,您将需要使用降级的 256 色方案。为此,只需在 colorchem 曝光行之前添加以下行:

let g:solarized_termcolors=256

let g:solarized_termcolors=256

Again, I recommend just changing your terminal colors to Solarized values either manually or via one of the many terminal schemes available for import.

同样,我建议您手动或通过多种可导入的终端方案之一将终端颜色更改为 Solarized 值。

回答by Will

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.

比尔特纳的答案有效,但有一种方法可以使颜色与 MacVim 完全匹配。Solarized 专门支持 iTerm2 以及其他终端仿真器。

  1. Go to the iterm2-colors-solarized github page
  2. Follow the instructions under "Installation"
  3. Make sure your .vimrc has the line colorscheme solarized
  1. 转到iterm2-colors-solarized github 页面
  2. 按照“安装”下的说明进行操作
  3. 确保你的 .vimrc 有一行 colorscheme solarized

This should set the vim colors in iTerm2 to be exactly as they are in gui editors.

这应该将 iTerm2 中的 vim 颜色设置为与 gui 编辑器中的颜色完全相同。

回答by dsandrade

A simple way to solve this problem is:

解决这个问题的一个简单方法是:

In colors dir on vim-color-solarized exist an arquive named 'solarozed.vim'

在 vim-color-solarized 的颜色目录中,存在一个名为“solarozed.vim”的文件

Open this file and search:
exe "let s:bg_back = ' ".s:vmode."bg=".s:back ."'"

打开这个文件并搜索:
exe "let s:bg_back = ' ".s:vmode."bg=".s:back ."'"

replace to:
exe "let s:bg_back = ' ".s:vmode."bg=".s:none ."'"

替换为:
exe "let s:bg_back = ' ".s:vmode."bg=".s:none ."'"

回答by Mike

I tried all of the previous suggestions. I just added set t_Co=256to .vimrc and it was fixed. I didn't need to create a tmuxalias or change my config file.

我尝试了所有以前的建议。我刚刚添加set t_Co=256到 .vimrc 并修复了它。我不需要创建tmux别名或更改我的配置文件。

回答by nlambert

For any still having issues like I was, I had installed iterm2 solarized color profile. Installing vim-color-solarizedto vim bundles and following the instructions was unnecessary and was incompatible. There were funny highlighting issues like in the screen capture above.

对于任何像我一样仍然有问题的人,我已经安装了 iterm2 solarized color profile。将vim-color-solarized安装到 vim 包并按照说明进行操作是不必要的并且不兼容。上面的屏幕截图中有一些有趣的突出显示问题。

Lesson learned: don't do both.

经验教训:不要两者都做。