Loading ...
Sorry, an error occurred while loading the content.

Patch to allow ctermfg or bg values as #rrggbb

Expand Messages
  • Matthew Wozniski
    Now that 88 and 256 color terminals are so ubiquitous, I find it frustrating that very few colorschemes support 256 color terminals. Unfortunately, writing a
    Message 1 of 33 , Nov 10, 2007
    • 0 Attachment
      Now that 88 and 256 color terminals are so ubiquitous, I find it
      frustrating that very few colorschemes support 256 color terminals.
      Unfortunately, writing a colorscheme that properly supports gvim, 88
      color terminals, and 256 color terminals requires looking up the color
      cube number that you want on at least one colorcube and often
      including scripting logic in the colorscheme itself to handle
      converting to the other cube (a la desert256 and inkpot).

      This patch intends to make it much easier to write 88 and 256 color
      schemes. This will allow a colorscheme author to write, for instance
      hi Normal cterm=none ctermfg=black ctermbg=#fffdfa
      and have vim behave as though the user had typed
      hi Normal cterm=none ctermfg=0 ctermbg=231
      (or, for 88 colors, hi Normal cterm=none ctermfg=0 ctermbg=79)
      based on the value of the t_Co setting.

      Not only does this take out the entire intermediate step of looking up
      colorcube values, it also will report the color that it chose as
      a cterm colorcube number when queried, making it very easy to tweak
      a single value to something the author feels more appropriate.

      Also, it is quite easy to convert an existing colorscheme to work with
      this patch; it usually is as simple as running a substitute:
      :%s/cterm.\{-}=.\{-}\>//g
      :%s/gui\zs\(fg\|bg\)\?=.\{-}\>/& cterm&/g

      I hope that others find this useful enough to include in future Vim
      releases. To that end, it also includes a patch to the relevant
      documentation, as well as a patch to the vim.vim syntax file to no
      longer highlight ctermfg=#rrggbb as an error.

      Feedback greatly appreciated.

      ~Matt Wozniski

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Ingo Karkat
      ... If you don t change your colorscheme often, CSApprox.vim (again, thanks Matt for this wonderful plugin!) allows to take a static snapshot, which avoids the
      Message 33 of 33 , Jul 24, 2010
      • 0 Attachment
        On 21-Jul-2010 20:57, Matt Wozniski wrote:
        > The down side is that it's a bit slow (as Dominique pointed out), but
        > I have a version in my sandbox that should hopefully help a bit with
        > that.

        If you don't change your colorscheme often, CSApprox.vim (again, thanks Matt for
        this wonderful plugin!) allows to take a static snapshot, which avoids the
        runtime penalty of translating all colors on each Vim launch; instead, only the
        generated snapshot is sourced.

        I have my own colorscheme, and here's how I generate a new snapshot whenever I
        have modified it (notice how I have put CSApprox in .vim/, not .vim/plugin/, so
        it's only sourced on-demand for this one-time conversion):

        gvim -c "runtime CSApprox.vim|CSApproxSnapshot!
        ~/.vim/colors/ingo-cterm.vim|quit"

        In my .vimrc, the following fragment detects a color terminal and then sources
        the snapshot. (Though this isn't strictly necessary, it falls back to the
        original, handwritten colorscheme when run in a plain terminal or the GUI.)

        let g:color_terminal = ! has('gui_running') && &t_Co >= 88
        if g:color_terminal
        " There may exist a high color snapshot of my colorscheme generated by
        " CSApprox.vim.
        try
        colorscheme ingo-cterm
        catch /^Vim\%((\a\+)\)\=:E185/ " catch error E185: Cannot find color scheme
        colorscheme ingo
        endtry
        else
        colorscheme ingo
        endif

        This works well for me, so I would recommend such an approach to try in case
        you're concerned about the startup performance.

        -- regards, ingo
        --
        -- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --
        -- http://vim.sourceforge.net/account/profile.php?user_id=9713 --

        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      Your message has been successfully submitted and would be delivered to recipients shortly.