I have a vim colorscheme vim-coogle, which uses both hex value and named colors already defined in vim, like:

hi Comment  guifg=#FFF59D  ctermfg=lightgrey

Now, the problem is, I want do define my own colors, eg, like:

let yellow2="#FFF59D"
hi Comment  guifg=yellow2  ctermfg=lightgrey

But, this is probably not as simple, as this thing dows not work.

How can I define new colors in vim colorscheme?


2 Answers 2


You could use :execute

execute printf('highlight Comment guifg=%s', yellow2)
  • Hi, Thanks for your reply. But will this solution make the color too slow? any clue?
    – BaRud
    Jul 6, 2020 at 13:14
  • @BaRud you’d need to profile and see; off the top of my head I’m not aware of any serious data collections on the performance of a colorscheme script (that runs once). Syntax highlighting is usually the slow culprit.
    – D. Ben Knoble
    Jul 6, 2020 at 13:15
  • Oh, did I read too much into the question? If this is all that's required I went too "big picture". :)
    – B Layer
    Jul 6, 2020 at 15:20

As far as I know the the finest granularity of any color element that can be modified in Vim is the "highlight group" (e.g. :hi Comment guifg=#FFF59D ....). Color "primitives" are dictated by the system. So "blue" means one thing in Windows GUI window and another in an xterm window.

While the system defined colors are either non-alterable or have to be changed in a system dependent way there may be additional colors specified in an "rgb.txt" file. This is apparently not available on all systems but I can attest to it being available in Windows. If you have it it should be in $VIMRUNTIME/rgb.txt. Here are a couple lines from my copy on Windows...

255 250 250     snow 
248 248 255     ghost white 
248 248 255     GhostWhite
245 245 245     white smoke

I haven't tried adding a new color but modifying these would be trivial.

If you have this file, great. If not try creating it with those pasted in lines and see if they seem to be recognized. Barring that you are probably relegated to using a system dependent method. Check Vim help for your system.

Update: Just tried adding my own color and it works fine.

Update2: For what it's worth I verified that this file exists and works in Cygwin and Ubuntu via WSL. Granted, it's still all, technically, Windows but @ChristianBrabandt just confirmed that the rgb.txt file is available and usable on all platforms.

I was able to edit existing color values as well as add new entries. You must be sure to save the changes to the original file and you'll need to quit vim and re-enter to see the changes. But other than that it's solid...as it should be for this apparently universal functionality.

  • Thanks for your reply. unfortunately, I got error: E254: Cannot allocate colour CRed where CRed is the color I have defined in rgb.txt as 255 0 0 CRed.
    – BaRud
    Jul 6, 2020 at 4:12
  • rgb.txt should always be available in $VIMRUNTIME. It will be installed there by make install Jul 6, 2020 at 12:53
  • @ChristianBrabandt Good to know. But does that mean its use is available everywhere, too? Vim help, as far as I can tell, mentions it only in association with Windows, BeOS and, sort of, "FVWM" (F Virtual Window Manager).
    – B Layer
    Jul 6, 2020 at 15:24
  • @BLayer yes, there are some parts in the code, that expect a rgb.txt file inside $VIMRUNTIME. Jul 6, 2020 at 15:28
  • @ChristianBrabandt Awesome, thanks. And I simultaneously verified it on WSL Ubuntu and Cygwin vims though, as my update desribes, it appears to only allow edits and not additions.
    – B Layer
    Jul 6, 2020 at 15:40

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.