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

发布于 2024-12-02 11:19:35 字数 432 浏览 1 评论 0原文

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

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

set background=dark
colorscheme solarized

终端中,配色方案看起来不正确: console vim

作为参考,这是它在 MacVim (gui vim) 下的样子 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:
console vim

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

乱世争霸 2024-12-09 11:19:35

有几件事需要检查:

  1. 在 iTerm2 中,在“首选项”中 ->个人资料 ->终端,在“终端仿真”下,将“报告终端类型:”设置为 xterm-256color。

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

    设置背景=暗
    “ 日晒选项 
    让 g:solarized_visibility = "高"
    让 g:solarized_contrast = "高"
    色彩方案 晒伤
    

    其中之一应该可以工作,但首先是 #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:

  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.

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 line let 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. Only let g:solarized_termcolors=256 if you are not using the solarized palette as your iTerm2 color preset.

指尖上的星空 2024-12-09 11:19:35

上面的答案对我不起作用。

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

如果上述解决方案也不适合您,请尝试此

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

更新:根据 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

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

Update: According to Jim Stewart, this works on Kitty too.

桃气十足 2024-12-09 11:19:35

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

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

打开 iTerm 2,打开首选项,单击首选项工具栏中的“配置文件”(以前称为“地址”,以前称为“书签”)图标,然后选择“颜色”选项卡。单击“加载预设”并选择“导入...”。选择 Solarized Light 或 Dark 主题文件。

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

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

或者:

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

修改 .vimrc

深色主题:

syntax enable
set background=dark
colorscheme solarized

syntax enable
set background=light
colorscheme solarized

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

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

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.

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

Or:

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

Modify .vimrc

Dark Theme:

syntax enable
set background=dark
colorscheme solarized

Light

syntax enable
set background=light
colorscheme solarized
爱人如己 2024-12-09 11:19:35

这对我在 OS X 10.9.1 的 iTerm 2 以及终端中有效。我犯的一个错误是将 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

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

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

colorscheme solarized
set background=dark
墨落画卷 2024-12-09 11:19:35

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

终端用户重要提示:

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

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

let g:solarized_termcolors=256

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

From the creator: 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:

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.

上课铃就是安魂曲 2024-12-09 11:19:35

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

这是我的修复方法。

  1. .vimrc

    语法启用
    设置背景=深色
    colorcheme Solarized

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

输入图像描述此处

  1. 将配置文件中的颜色预设设置为 Solarized Dark

在此处输入图像描述

I struggled with the same problem on 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.

enter image description here

  1. Set color preset in the profile to Solarized Dark

enter image description here

乙白 2024-12-09 11:19:35

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

  1. 转到 iterm2- colors-solarized github 页面
  2. 按照“安装”下的说明进行操作
  3. 确保您的 .vimrc 中有行 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.

  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

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

一个人的夜不怕黑 2024-12-09 11:19:35

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

在 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 ."'"

明媚如初 2024-12-09 11:19:35

对于像我一样仍然遇到问题的人,我安装了 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.

ˇ宁静的妩媚 2024-12-09 11:19:35

我尝试了之前的所有建议。我刚刚将 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 a tmux alias or change my config file.

和我恋爱吧 2024-12-09 11:19:35

以前的答案都不适合我。显然我失踪了:

set termguicolors

None of the previous answers worked for me. Apparently I was missing:

set termguicolors
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文