iterm vim colorscheme not working

风流意气都作罢 提交于 2019-12-17 21:53:14

问题


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


回答1:


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



回答2:


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

:syntax enable



回答3:


To those who still have problem.

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




回答4:


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
    



回答5:


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.



来源:https://stackoverflow.com/questions/3761770/iterm-vim-colorscheme-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!