Question

I'm disappointed because of the vim behaviour under Ubuntu 13.04 and the issues I'm having the color reproduction.

I have problems when setting a colorscheme and I also tried to fix this issue with set t_Co=256 but I can do anything and nothing changes. I also tried different terminal emulators a and different settings but really nothing changes.

I tried Gvim and apparently it handles the colors correctly nd I have a much more consistent behaviour, now my question is: what am I missing when using gvim instead of vim?

I'm a new vim user so I don't know the potential of these two applications.

EDIT: For example this is how the darkblue theme looks like under vim running in gnome-terminal enter image description here

Was it helpful?

Solution

Assuming your Ubuntu environment is correctly set up (and judging from the screenshot, it is), you're probably just disappointed that most colorschemes don't come with high color support in the terminal.

You can use the CSApprox plugin (or one of its alternatives) to translate a GUI colorscheme to a high-color (i.e. 88-256 color) terminal. That will get you a closer approximation.

OTHER TIPS

Terminal Vim, especially when you want to use high-color colorschemes, is indeed more work to set up. However, you'll find a plethora of articles and tips on the Web. Since you didn't tell your precise problems, just two tips:

  1. Ensure that the colorscheme supports high-color terminals (some are GVIM-only)
  2. Use a modern terminal emulator like gnome-terminal, and properly set the TERM variable (i.e. gnome-256color); this avoids messing with :set t_Co, which is a hack.

GVIM

Pros

Visually, you gain some additional highlighting capabilities like the undercurl for spelling errors, and the full 24-bit RGB spectrum of colors.

You also have more keys available for mapping (or at least, more keys are straightforward to map without having to delve into key code and terminal issues).

Cons

If your Vim workflow heavily interacts with the shell, i.e. if you execute lots of external :!shell-command, or :make, or launch a :shell from within Vim, only the terminal offers full capabilities; GVIM only has a primitive terminal emulation built-in, so some output may be wrong or is missing highlighting.


I personally do most of my editing in GVIM, but occasionally start Vim in a terminal (e.g. to edit Linux config files or through SSH).

The vanilla colorschemes can't make assumptions about the number of colors, so they are conservative and expect only the 16 basic colors of the PC era.

Setting up color for vim in 256 color XTerm is a bit more involved, but the result is pleasing. Here's what I use. Be sure that your XTerm is actually a 256 color version (it is by default on Ubuntu). This setup will make both vim and gvim use the same colors. As a bonus, if you have configured your XTerm to use TrueType fonts, it can render highlight as italic--see the white comments (if the font supports it; I use *faceName: Droid Sans Mono).

enter image description here

" If the xterm supports 256 colors, make sure TERM=xterm-256color.
" If it supports 256 colors but sets TERM=xterm, edit the appropriate
" resource file (~/.Xdefaults or $XAPPLRESDIR/XTerm) and add
" *termName: xterm-256color
" For mintty, select the xterm-256color TERM value in the options menu.
if &term == "xterm-256color"
  " Also for Cygwin's mintty.
  set t_Co=256
elseif $PROFILE_OS == "Solaris"
  set t_Co=256
elseif (&term == "xterm" || &term =~ "cons") && $TTY =~ "/dev/ttyv"
  " Adjust for FreeBSD syscons with ANSI colors.
  set t_Co=16
  map <Esc>[2~ i
  map <Esc>[3~ x
  map <Esc>[5~ <C-B>
  map <Esc>[6~ <C-F>
  colorscheme delek
elseif &term == "cygwin"
  " Adjust for Cygwin in a cmd.exe window.
  set t_Co=16
  colorscheme koehler
endif
"
" The cterm color numbers refer to XTerm colors in 256 color mode.
" Map rgb to cterm colors using <URL:https://gist.github.com/719710>.
" cterm=underline is rendered as italic with xterm +ulit
" gui=NONE turns off bold, italic.
"
" Normal must be set before colors "fg" and "bg" can be used.
highlight Normal ctermfg=216 ctermbg=233 guifg=#ffaf87 guibg=#121212

" pink        C 'c'
highlight Character
\ cterm=NONE      ctermfg=211     ctermbg=bg
\ gui=NONE        guifg=#ff87af   guibg=bg
" gray        This comment.
highlight Comment
\ cterm=underline ctermfg=250     ctermbg=bg
\ gui=italic      guifg=#bcbcbc   guibg=bg
highlight ColorColumn  cterm=NONE ctermfg=7   ctermbg=99  gui=NONE guifg=#c0c0c0 guibg=#875fff
" blue        if/then/else/fi.
highlight Conditional
\ cterm=NONE      ctermfg=27      ctermbg=bg
\ gui=NONE        guifg=#005fff   guibg=bg
" lightgreen  Numbers and quoted strings.
highlight Constant
\ cterm=NONE      ctermfg=82      ctermbg=bg
\ gui=NONE        guifg=#5fff00   guibg=bg
highlight Cursor
\ cterm=NONE      ctermfg=black   ctermbg=red
\ gui=NONE        guifg=black     guibg=red
highlight CursorColumn cterm=NONE ctermfg=7   ctermbg=97  gui=NONE guifg=#c0c0c0 guibg=#875faf
highlight DiffAdd      cterm=NONE ctermfg=8   ctermbg=24  gui=NONE guifg=#808080 guibg=#005f5f
highlight DiffChange   cterm=NONE ctermfg=8   ctermbg=56  gui=NONE guifg=#808080 guibg=#5f00d7
highlight DiffDelete   cterm=NONE ctermfg=8   ctermbg=88  gui=NONE guifg=#808080 guibg=#870000
highlight DiffText     cterm=NONE ctermfg=8   ctermbg=90  gui=NONE guifg=#808080 guibg=#870087
" Status line.
highlight Error
\ cterm=NONE      ctermfg=196     ctermbg=234
\ gui=NONE        guifg=#ff0000   guibg=black
highlight ErrorMsg
\ cterm=NONE      ctermfg=172     ctermbg=black
\ gui=NONE        guifg=orange    guibg=black
highlight Folded
\ cterm=NONE      ctermfg=112     ctermbg=235
\ gui=NONE        guifg=#87d700   guibg=#262626
highlight FoldColumn
\ cterm=NONE      ctermfg=112     ctermbg=235
\ gui=NONE        guifg=#87d700   guibg=#262626
" green       Function names (has()).
highlight Function
\ cterm=NONE      ctermfg=46      ctermbg=bg
\ gui=NONE        guifg=#00ff00   guibg=bg
" lightyellow Names.
highlight Identifier
\ cterm=NONE      ctermfg=139     ctermbg=bg
\ gui=NONE        guifg=#af87af   guibg=bg
highlight Include
\ cterm=NONE      ctermfg=50      ctermbg=bg
\ gui=NONE        guifg=#00ffd7   guibg=bg
highlight LineNr
\ cterm=underline ctermfg=244     ctermbg=237
\ gui=italic      guifg=#808080   guibg=#3a3a3a
highlight Macro
\ cterm=NONE      ctermfg=203     ctermbg=bg
\ gui=NONE        guifg=#ff5f5f   guibg=bg
" --More--
highlight MoreMsg
\ cterm=NONE      ctermfg=123     ctermbg=238
\ gui=NONE        guifg=#87ffff   guibg=#444444
" --INSERT--
highlight ModeMsg
\ cterm=NONE      ctermfg=123     ctermbg=238
\ gui=NONE        guifg=#87ffff   guibg=#444444
" Tilde and @ at the end of the window.
highlight NonText
\ cterm=bold      ctermfg=cyan    ctermbg=bg
\ gui=bold        guifg=cyan      guibg=bg
highlight Operator
\ cterm=NONE      ctermfg=129     ctermbg=bg
\ gui=NONE        guifg=#af00ff   guibg=bg
highlight PmenuSbar    cterm=NONE ctermfg=fg  ctermbg=32  gui=NONE guifg=fg      guibg=#0087d7
" medium blue #if/#else/#endif ${foo}
highlight PreProc
\ cterm=NONE      ctermfg=75      ctermbg=bg
\ gui=NONE        guifg=#5fafff   guibg=bg
" Hit-enter and yes/no questions.
highlight Question
\ cterm=NONE      ctermfg=green   ctermbg=bg
\ gui=NONE        guifg=green     guibg=bg
highlight Search
\ cterm=NONE      ctermfg=153     ctermbg=237
\ gui=NONE        guifg=cyan      guibg=gray10
" violett     <F11>, printf %s, `cmd`
highlight Special
\ cterm=bold      ctermfg=125     ctermbg=bg
\ gui=bold        guifg=#af005f   guibg=bg
" violett     <F11> in map
highlight SpecialKey
\ cterm=NONE      ctermfg=135     ctermbg=bg
\ gui=NONE        guifg=#af5fff   guibg=bg
highlight SpellBad
\ cterm=NONE      ctermfg=88      ctermbg=140
\ gui=NONE        guifg=#870000   guibg=#af87d7
highlight SpellCap
\ cterm=NONE      ctermfg=88      ctermbg=138
\ gui=NONE        guifg=#870000   guibg=#af8787
highlight SpellLocal
\ cterm=NONE      ctermfg=118     ctermbg=236
\ gui=NONE        guifg=#87ff00   guibg=#303030
highlight SpellRare
\ cterm=NONE      ctermfg=19      ctermbg=75
\ gui=NONE        guifg=#0000af   guibg=#5fafff
" lightblue   Keywords (highlight).
highlight Statement
\ cterm=NONE      ctermfg=44      ctermbg=bg
\ gui=NONE        guifg=#00d7d7   guibg=bg
highlight StatusLine
\ cterm=bold      ctermfg=41      ctermbg=239
\ gui=bold        guifg=#00d75f   guibg=#4e4e4e
highlight StatusLineNC
\ cterm=NONE      ctermfg=245     ctermbg=239
\ gui=NONE        guifg=#8a8a8a   guibg=#4e4e4e
" olive       static, const, volatile
highlight StorageClass
\ cterm=NONE      ctermfg=98      ctermbg=bg
\ gui=NONE        guifg=#875fd7   guibg=bg
" green       ''foo''
highlight String
\ cterm=NONE      ctermfg=35      ctermbg=bg
\ gui=NONE        guifg=#00af5f   guibg=bg
" titles for output from ":set all", ":autocmd" etc.
highlight Title
\ cterm=NONE      ctermfg=123     ctermbg=238
\ gui=NONE        guifg=#87ffff   guibg=#444444
" TODO XXX
highlight Todo
\ cterm=bold      ctermfg=161     ctermbg=181
\ gui=bold        guifg=#d7005f   guibg=#d7afaf
" lightbeige  int, long, ... ctermfg
highlight Type
\ cterm=NONE      ctermfg=170     ctermbg=bg
\ gui=NONE        guifg=#d75fd7   guibg=bg
" gray        Visual selection
highlight Visual
\ cterm=NONE      ctermfg=215     ctermbg=238
\ gui=NONE        guifg=burlywood guibg=gray30
" gray        Visual selection
highlight VisualNOS
\ ctermfg=215     ctermbg=238     ctermbg=bg
\ gui=NONE        guifg=#5090c0   guibg=gray30
highlight WarningMsg
\ cterm=NONE      ctermfg=green   ctermbg=black
\ gui=NONE        guifg=green     guibg=black
highlight WildMenu
\ cterm=NONE      ctermfg=23      ctermbg=148
\ gui=NONE        guifg=#005f5f   guibg=#afd700

if &term == "xterm-256color" && $DISPLAY == ""
  " Cygwin mintty doesn't do italic.
  highlight Comment cterm=NONE
  highlight LineNr  cterm=NONE
endif

The 6x6x6 colorcube to chose the cterm color numbers from:

enter image description here

GVim is not much more than Vim with a GUI and better color support: there shouldn't be any deep difference between how you use both.

set t_Co=256 is not a proper solution to any colorscheme issue. If you want colorful colorschemes in Vim the only thing to do is to setup your terminal emulator to advertise itself as "capable of displaying 256 colors". How you do it depends on your terminal emulator but it generally boils down to setting the TERM environment variable to xterm-256color or similar value. You don't need to do anything else.

There are thousands of Vim colorschemes to choose from, some are GUI-only, some are terminal-only… make sure you choose a colorscheme that suits your usage. GUI colorscheme can use thousands of colors but CLI colorschemes are limited to the Xterm 256 colors palette; this tends to make GUI colorschemes "prettier" but not necessarily more useful.

If there's no hint in the name of the colorscheme or its README/description, you can open it and look for guibg and ctermbg. If you have ctermbg (or ctermfg…) the colorscheme is mostly guaranteed to work in a 256 colors-capable terminal emulator. If you have guibg the colorscheme will work in GVim. If you have both, you can have the same colorscheme for Vim and GVim.

Of course, YMMV.

Also, see this other answer of mine to a similar question.

I used to be a Vim user, and switch to GVim because of the same kind of issue, namely color scheme incompatibility.

Initially I did not like the visual clutter added by all the buttons, scroll bar and menus of the Gvim window.

Fortunately, you can hide all that and get something really close to a Vim console by using the following code in your .vimrc :

if has("gui_running")
    " GUI is running or is about to start.
    " Maximize gvim window.
    set lines=120 columns=140  

    " Display or hide menu when using gVim
    function! ToggleGUICruft()
      if &guioptions=='i'
        exec('set guioptions=imTrL')
      else
        exec('set guioptions=i')
      endif
    endfunction

    map <F11> <Esc>:call ToggleGUICruft()<cr>

    " by default, hide gui menus
    set guioptions=i

endif

You can now use F11 to toggle menus & scroll bars.

I have not found any downside to GVim so far. If you are a new user, the menu can actually be helpful to discover new commands.

Ok, apparently any terminal emulator that I have tried ( xterm, gnome-terminal, ... ) is capable of managing 8 or 256 colors depending on both X11 settings, VGA drivers and the value of the environment variable TERM. So the top choice is 256 color and if you are looking for something better you have no other choice than picking gvim as your editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top