简体   繁体   中英

Can't use vim themes in iTerm or Terminal

First i know about t_Co, TERM=xterm-256colors, etc. And i can't use macVim or gvim because i need it in ssh. But when i set up theme in vim(every, except peaksea) i get:

在此处输入图片说明

I found a "solution", it is connected with ansi colors. When we change it here:

在此处输入图片说明

the colors changes. For solarized theme i found a term theme with other ansi colors(near to solarized) and it works fine. But when i need another theme i should setup ansi for this theme. The question is how can i set theme without using standard ansi colors? And if we can't why peaksea works fine and don't use ANSI colors(i tried change it)?

PS: iTerm everything is the same.

PS2: One interesting thing that on airline all colours are valid.

Vim colorizes text in the terminal through ANSI color codes. Here's an example:

:highlight Comment ctermfg=Cyan ctermbg=Black

Cyan and Black translate to ansi color numbers. You can even specify the numbers in the highlight command instead of Cyan and Black. See the help file:

:help cterm-colors

When a terminal supports 256 colors someone authoring a colorscheme has more to choose from, but the options are still limited to the defined 256 colors ( http://www.pixelbeat.org/docs/terminal_colours/ ). The peaksea authors chose colors from the existing 256 options and that's why it works without reconfiguring colors in the terminal prefrences. Here's a snippet from peaksea.vim

hi Normal       ctermfg=252 ctermbg=234 cterm=NONE

Airline also uses colors from the existing 256 palette. https://github.com/bling/vim-airline/blob/master/autoload/airline/themes/base16.vim

" Color palette
let s:gui_dark_gray = '#202020'
let s:cterm_dark_gray = 234

In the case above, the the 'gui' codes are for MacVim/gVim and cterm are for terminals.

If a color scheme author wants to use colors that are not available in the 256 color palette, they have to configure the terminal to temporarily override the rgb color value for a given number. This can be done with a script as well as the preferences menu of the terminal application. See https://github.com/chriskempson/base16-shell . This can be done in a way where the first 16 numbers are left unmodified. But, if vim uses number 20 for red, all programs that use number 20 on the terminal will get translated to red.

I created a test and proved to myself that it would work. Here's the gist. https://gist.github.com/cskeeters/9674586

Another alternative, would be to find the colorshemes you like and change them to use the closest colors from the 256 color palette rather than use 0-16 and rely on terminal configuration. The airline themes may give you a jumpstart like it did for base16 in the link above.

The colortrans.py gist https://gist.github.com/MicahElliott/719710 can be used to map the base16-builder color scheme rgb values into the closest 256 color numbers.

https://github.com/chriskempson/base16-builder/blob/master/schemes/default.yml

cat ../base16-builder/schemes/default.yml | sed -nre 's/base(..): "(.*)"/\2/p' | xargs -I {} ./colortrans.py {}

RGB 151515 -> xterm color approx 16 (000000)
RGB 202020 -> xterm color approx 16 (000000)
RGB 303030 -> xterm color approx 59 (5f5f5f)
RGB 505050 -> xterm color approx 59 (5f5f5f)
RGB b0b0b0 -> xterm color approx 145 (afafaf)
RGB d0d0d0 -> xterm color approx 188 (d7d7d7)
RGB e0e0e0 -> xterm color approx 188 (d7d7d7)
RGB f5f5f5 -> xterm color approx 231 (ffffff)
RGB ac4142 -> xterm color approx 131 (af5f5f)
RGB d28445 -> xterm color approx 173 (d7875f)
RGB f4bf75 -> xterm color approx 216 (ffaf87)
RGB 90a959 -> xterm color approx 107 (87af5f)
RGB 75b5aa -> xterm color approx 109 (87afaf)
RGB 6a9fb5 -> xterm color approx 73 (5fafaf)
RGB aa759f -> xterm color approx 139 (af87af)
RGB 8f5536 -> xterm color approx 95 (875f5f)

If you break down and just want to reconfigure the terminal for each theme you use, know that you can import color presets in iTerm. Many are available from https://github.com/chriskempson/base16-iterm2 . Then you just need to call ":colorscheme schemeName' in vim (or putting it in your .vimrc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM