3

How to define a specified RGB value as color with customized name in Vim script, much like the existing color Black, Gray, etc.

  • 3
    Please give more background; what is your final goal? When a question is only about a small technical step, it's difficult to provide a good answer. If you don't tell us why you want this, it's easy to succumb to the XY problem. – Ingo Karkat May 26 '15 at 10:39
4

tl;dr: it seems you can't do this. Sorry :-(


Longer:

For terminals, there is a static list of 28 colors in syntax.c which defined the names (around line 7306):

static char *(color_names[28]) = {
            "Black", "DarkBlue", "DarkGreen", "DarkCyan",
            "DarkRed", "DarkMagenta", "Brown", "DarkYellow",
            "Gray", "Grey",
            "LightGray", "LightGrey", "DarkGray", "DarkGrey",
            "Blue", "LightBlue", "Green", "LightGreen",
            "Cyan", "LightCyan", "Red", "LightRed", "Magenta",
            "LightMagenta", "Yellow", "LightYellow", "White", "NONE"};

The exact value of those colours will depend on your terminal, but the most used is probably:

/* for xterm with 256 colors... */
static int color_numbers_256[28] = {0, 4, 2, 6,
                                    1, 5, 130, 130,
                                    248, 248,
                                    7, 7, 242, 242,
                                    12, 81, 10, 121,
                                    14, 159, 9, 224, 13,
                                    225, 11, 229, 15, -1};

There is no way I see in the code to add a colour name from VimScript.

For gVim, the code is slightly different. The function gui_mch_get_color() in the gui_*.c files handles this. The precise content differs for every GUI backend,

For example, for the GTK2 GUI it uses the gdk_color_parse() function, for X11 it uses XParseColor, and for Windows it seems to use a static list. Perhaps some of these systems allow defining custom colour names; but this is not something you can do from within VimScript as such.

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.