iterm vim 颜色方案不起作用

发布于 2024-09-24 23:31:20 字数 309 浏览 0 评论 0原文

当我在 iTerm 中从命令行运行 vim 时,语法突出显示似乎在本地不起作用。

例如,在 vim 中,我安装了一个很好的颜色方案,它在 MacVim 中运行得很好,但如果在 iTerm 中也能显示相同的颜色方案,那就太好了。

我有什么想法可以打开它吗?

这是我尝试使用的配色方案 http://www.vim.org/scripts/script.php?script_id=2340

When I run vim from the command line in iTerm, syntax highlighting doesn't seem to work locally.

In vim for example I have installed a nice colorscheme that works quite well in MacVim but it would be great if in iTerm it showed the same one.

Any ideas how I can turn this on?

This is the color scheme I'm trying to use
http://www.vim.org/scripts/script.php?script_id=2340

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

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

发布评论

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

评论(7

债姬 2024-10-01 23:31:20

为了在 vim 中打开代码高亮,请尝试启用语法插件:

:syntax enable

In order to turn code highlighting on in vim, try to enable the syntax plugin:

:syntax enable
不语却知心 2024-10-01 23:31:20

该配色方案看起来只支持 256 色终端。如果 Vim 认为您的终端仅支持 8 种颜色,您将不会看到该特定的配色方案。

您可以通过以下方式在 Vim 中检查这一点:

:echo &t_Co

如果返回 8,则可能是问题所在。尝试在 ~/.vimrc 中将其设置为 256,看看是否有帮助:

let &t_Co=256

That color scheme looks like it only supports 256-color terminals. If Vim thinks that your terminal only supports 8 colors, you won't see that specific color scheme.

You can check this in Vim by:

:echo &t_Co

If that returns 8, this might be the problem. Try setting it to 256 in your ~/.vimrc and see if that helps:

let &t_Co=256
挽清梦 2024-10-01 23:31:20

对于那些仍然有问题的人。

i学期 2 ->首选项->个人资料 ->颜色 ->最小对比度->最低

setup

To those who still have problem.

iTerm 2 -> Preferences -> Profiles -> Colors -> Minimum contrast -> lowest

setup

紅太極 2024-10-01 23:31:20

我以前遇到过这个问题,以及一些相关的问题,所以我将总结一下我发现的内容。

  1. 确保 iTerm 设置为使用 256 色。在命令行尝试 $ echo $TERM,如果没有看到 xterm-256color,请按照说明操作 在此答案中

  2. 设置您的 vimrc 来处理其他终端。例如,Snow Leopard 中的常规终端仅支持 8 种颜色,如果您尝试使用 256 色配色方案,则会闪烁(在这种情况下我只是不设置一种颜色)。这是我所拥有的:

    " 在 GNOME 终端中启用 256 色(对于我的 Ubuntu VM)
    if $COLORTERM == 'gnome-terminal'
        设置 t_Co=256
    恩迪夫
    
    " 设置您的配色方案(将 wombat 替换为您的配色方案)
    “如果您使用的是 gvim 或 macvim,那么您的配色方案可能有一个版本
    “使用超过 256 种颜色
    如果有(“gui_running”)
        色彩方案袋熊
    elseif &t_Co == 256
        颜色方案袋熊256
    恩迪夫
    
    " 打开特定于语言的语法突出显示
    语法上
    

I've had this problem before, as well as some related issues, so I'll summarize what I found.

  1. Make sure iTerm is set to use 256 colors. Try $ echo $TERMat the command line, and if you don't see xterm-256color then follow the directions in this answer.

  2. Set up your vimrc to handle other terminals as well. The regular Terminal in Snow Leopard only supports 8 colors for instance and will blink if you try to use a 256 color color scheme (I just don't set one in that case). Here's what I have:

    " enable 256 colors in GNOME terminal (for my Ubuntu VM)
    if $COLORTERM == 'gnome-terminal'
        set t_Co=256
    endif
    
    " set your color scheme (replace wombat with whatever yours is called)
    " if you're using a gvim or macvim, then your color scheme may have a version
    " that uses more than 256 colors
    if has("gui_running")
        colorscheme wombat
    elseif &t_Co == 256
        colorscheme wombat256
    endif
    
    " turn on language specific syntax highlighting
    syntax on
    
×纯※雪 2024-10-01 23:31:20

在尝试了这里所有其他答案之后,我最后需要的是:

set termguicolors

After trying all the other answers here, the final thing I needed was:

set termguicolors
白云不回头 2024-10-01 23:31:20

尽管遵循了这个(以及其他类似)问题中的所有建议,但我最终在几年前从网络上的某个地方获取的 vimrc 的一个被遗忘的部分中发现了我的麻烦(因为它组织得相当好),然后进行了广泛的修改为了我自己的目的。

但问题区域出在我从未接触过的一小部分设置中,回到我开始使用的原始文件中。 .vimrc 的相关部分是:

   " GVIM- (here instead of .gvimrc)
   if has('gui_running')
          set guioptions-=T               " remove the toolbar
          set lines=40                    " 40 lines of text instead of 24,
   else
           set term=builtin_ansi       " Make arrow and other keys work
   endif

毫不奇怪(回想起来),“set term”行会重置一些东西,这样无论你的终端在 TERM 环境变量中报告什么类型,你最终都会得到一个通用的 8 色 ANSI终端。在 .vimrc 中显式设置 'term' 可能是一个非常糟糕的主意,就像直接设置 t_Co 一样。

我删除了整个块(并将 gvim 设置放入它们所属的 .gvimrc 中),从那时起,一切都对我来说正常工作。

Despite following all the advice in this (and other, similar) questions, I eventually found my trouble in a forgotten part of a vimrc I had taken from somewhere on the web years ago (because it was rather nicely organised), and then extensively modified for my own purposes.

But the problem area was in a little group of settings that I had never touched, back in the original file I started with. The relevant bit of the .vimrc was:

   " GVIM- (here instead of .gvimrc)
   if has('gui_running')
          set guioptions-=T               " remove the toolbar
          set lines=40                    " 40 lines of text instead of 24,
   else
           set term=builtin_ansi       " Make arrow and other keys work
   endif

Unsurprisingly (in retrospect), that "set term" line resets things so that regardless of what type your terminal is reporting in the TERM environment variable, you wind up with a generic, 8-color ANSI terminal. Setting 'term' explicitly inside the .vimrc is probably a very bad idea, just like setting t_Co directly.

I removed this whole block (And put the gvim settings into .gvimrc, where they belong), and everything has been working correctly for me ever since.

但可醉心 2024-10-01 23:31:20

编辑 sudo vim ~/.vimrc 并添加“语法”应该可以解决问题。

Edit sudo vim ~/.vimrc and add "syntax on" should fix issue.

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