I am using altercation's vim-solarized plugin to set my default colorscheme and have set my xterm to use solarized colors as well.

When I try to run :TOhtml on a buffer, say on $MYVIMRC, the resulting html file has different colors than it is supposed to have.

How can I get the "right" colors/colorscheme for the html file?

  • You can check that your terminal doesn't alter the actual solarized colors. It may lead to the issue that the generated colors are correct but your terminal are displaying them differently. – nobe4 Aug 23 '15 at 10:19
  • If I set my xterm colorscheme to White on Black and then just run vim, the colors are completely off (neither standard vim colors nor solarized vim colors). If I instead run vim -u NONE -N (not sourced my vimrc but still nocompatible enabled), the colors are standard vim colors. So indeed solarized colors in vim only seem to work for me when I set the appropriate xterm colors as well. Do you know why I might have this issue? – cbaumhardt Aug 23 '15 at 11:11
  • Is it just me, or does syntax highlighting cause more problems than it solves? – Antony Jul 27 '16 at 11:22

You can't get the "right" colors in a terminal emulator because the colors used for highlighting are defined as "red" or "bright cyan" which are then user-defined at the terminal emulator level and could mean anything, especially in the case of Solarized where "bright cyan" is actually a freaking grey.

You can get the "right" colors in GVim, though, because syntax highlighting is done with fixed values.

  • Technically, you can also get the correct colors in a terminal, provided that you install a solarized color theme for the terminal. But yes, you can't do that in Vim alone. – Sato Katsura Aug 23 '15 at 11:26
  • Ok. So I need to change the colors of my terminal emulator to the solarized colors (that is how I have it anyway the whole time) - everything looks great then. But using the :TOhtml command will create a html file then with colors looking different than the solarized ones I see in vim. Is there a way to create a html file with the solarized colors? – cbaumhardt Aug 23 '15 at 11:45
  • @SatoKatsura, when run in a terminal, Vim doesn't have access to the actual rgb/hex value of "red" or "13" so :TOhtml can't accurately use the user-defined color in the generated HTML. The only way to get an output that looks like what you have in Vim is to run :TOhtml in GVim/MacVim. – romainl Aug 23 '15 at 11:45
  • @cbaumhardt, you didn't get it, did you? You can't obtain what you want in Vim. Only in GVim. – romainl Aug 23 '15 at 11:47
  • I did indeed not get it with your previous answer. Thank you for clarification. – cbaumhardt Aug 23 '15 at 12:01

I use terminal Vim on Cygwin Mintty with both using solarized scheme on Windows. I've got the same problem and found a workaround which is not perfect but might be suitable for you.

My goal was to copy syntax highlighted code to E-Mails and documents. For this to achieve, I don't have to generate HTML. I configured Mintty terminal to copy rich text:

  1. Right-Click the title
  2. Options...
  3. Mouse
  4. Select 'Copy as rich text'

As I use the solarized dark scheme in Vim, I paste the content to other applications and remove the background color there. The result looks fine:

VIM with solarized dark scheme:

VIM with solarized dark scheme

Pasted to MS Word with background color removed manually:

Pasted to MS Word with background color removed manually

Unfortunately, with this solution, you lose the ability to Vim-select the text. This brings problems with splits and line numbers. But you can close all splits and remove the line numbers using :set nonumber.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.