开发者

iterm vim colorscheme not working

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 o开发者_运维问答n?

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


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

:syntax enable


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


To those who still have problem.

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

iterm vim colorscheme not working


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
    


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.


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

set termguicolors


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜