Fix color in vim or take a decisive step?

I am disappointed with the vim behavior in Ubuntu 13.04 and the problems that I have when reproducing colors.

I am having problems setting colorscheme and I also tried to fix this problem with set t_Co=256 , but I can do anything and nothing changes. I also tried different terminal emulators and different settings, but nothing really changes.

I tried Gvim and apparently handled the colors correctly. I have much more consistent behavior, now my question is: what am I missing when using gvim instead of vim?

I am a new vim user, so I do not know the capabilities of these two applications.

EDIT: For example, darkblue theme looks like vim running in gnome-terminal enter image description here

+7
source share
6 answers

Assuming your Ubuntu environment is configured correctly (and judging by the screenshot, it is), you are probably just disappointed that most colors do not have high color support in the terminal.

You can use the CSApprox plugin (or one of its alternatives) to convert the color scheme of the graphical interface to a high-color (i.e. 88-256 color) terminal. This will bring you closer.

+6
source

Vim terminal, especially if you want to use the color colors of flowers, is really more suitable for customization. However, you will find many articles and tips on the Internet. Since you did not indicate your exact problems, there are just two tips:

  • Make sure colorscheme supports high-color terminals (some of them are GVIM only)
  • Use a modern terminal emulator, for example gnome-terminal , and set the TERM variable correctly (i.e. gnome-256color ); this avoids messing around with :set t_Co , which is a hack.

Gvim

Pros

Visually, you get additional highlighting options, such as under-spelling errors and a full 24-bit range of RGB colors.

You also have several keys available for matching (or at least more keys are easy to match without having to delve into the key code and problems with the terminal).

Against

If your Vim workflow interacts strongly with the shell, that is, if you execute many external :!shell-command or :make or run :shell from Vim, only the terminal offers full capabilities; GVIM has only primitive terminal emulation, so some output may be incorrect or there may be no backlight.


I personally do most of my editing in GVIM, but sometimes I run Vim in the terminal (for example, to edit Linux configuration files or through SSH).

+6
source

Vanilla colors cannot make assumptions about the number of colors, so they are conservative and expect only 16 primary colors of the PC era.

Color adjustment for vim in 256 color XTerm is a bit more complicated, but the result is nice. Here is what I use. Make sure your XTerm is actually a 256-color version (the default is Ubuntu). This setting will force both vim and gvim to use the same colors. As a bonus, if you configured your XTerm to use TrueType fonts, it can highlight italics - see 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 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~ <CB> map <Esc>[6~ <CF> 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 

6x6x6 color cube for selecting cterm color numbers:

enter image description here

+3
source

GVim is not much bigger than Vim with a GUI and enhanced color support: there should be no deep difference between how you use both.

set t_Co=256 not the right solution for any color issue. If you want vibrant colors in Vim, the only thing you need to do is set up a terminal emulator to advertise yourself as "capable of displaying 256 colors." How you do this depends on your terminal emulator, but usually it comes down to setting the TERM environment variable to xterm-256color or a similar value. You do not have to do anything.

There are thousands of Vim colors to choose from, some of them are GUI only, some are only for terminals ... make sure you select a color scheme that is suitable for your use. The GUI color scheme can use thousands of colors, but CLI color colors are limited to the Xterm 256 color palette; this usually makes the graphic characters β€œprettier”, but not necessarily more useful.

If there is no hint of the name colorscheme or its README / description, you can open it and look for guibg and ctermbg . If you have ctermbg (or ctermfg ...), then most colors are guaranteed to work in a terminal emulator with 256 colors. If you have guibg , then Color Colors will work in GVim. If you have both options, you can have the same color scheme for Vim and GVim.

Of course, YMMV.

Also see this other my answer to a similar question .

+1
source

I used to be a Vim user and switched to GVim due to the same problem, namely color scheme incompatibility.

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

Fortunately, you can hide it all and get something really close to the Vim console using the following code in .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 

Now you can use F11 to switch menus and scrollbars.

I have not yet found flaws in GVim. If you are a new user, a menu may be useful for discovering new commands.

+1
source

Well, apparently, any terminal emulator I tried (xterm, gnome-terminal, ...) is able to control 8 or 256 colors depending on the settings of X11, VGA drivers and the value of the TERM environment variable. Thus, the best choice is 256 colors, and if you are looking for something better, you have no choice but to choose gvim as your editor.

0
source

All Articles