Skip to content

Commit 0f4054f

Browse files
committed
runtime(colors): color names in the v:colornames dict should be lower cased
Vim will lookup color names from the v:colornames dictionary by its lower case color name. So when sourcing the v:colornames dictionary, make sure to convert upper case color names to lower case. Also, while at it, mention in the documentation, that the dictionary should contain lower case names only. fixes: #13976 Signed-off-by: Christian Brabandt <[email protected]>
1 parent de7f5bd commit 0f4054f

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

runtime/colors/lists/csscolors.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
" Similar in spirit to rgb.txt, this plugin establishes a human-friendly name
55
" for every color listed in the CSS standard:
66
"
7+
" Note: the color names should be in lower case, because Vim will lookup the
8+
" a color by its lower case name.
9+
"
710
" https://www.w3.org/TR/css-color-3/
811

912
let s:keepcpo= &cpo
@@ -26,7 +29,6 @@ call extend(v:colornames, {
2629
\ 'css_blue': '#0000FF',
2730
\ 'css_teal': '#008080',
2831
\ 'css_aqua': '#00FFFF',
29-
\
3032
\ 'css_aliceblue': '#f0f8ff',
3133
\ 'css_antiquewhite': '#faebd7',
3234
\ 'css_aquamarine': '#7fffd4',
@@ -160,6 +162,14 @@ call extend(v:colornames, {
160162
\ 'css_yellowgreen': '#9acd32',
161163
\ }, 'keep')
162164

165+
" all keys should be in lower case, convert keys that are not yet
166+
for [key, val] in items(filter(copy(v:colornames), { key -> key =~ '\u'}))
167+
call remove(v:colornames, key)
168+
if !has_key(v:colornames, tolower(key))
169+
call extend(v:colornames, {tolower(key): val}, 'keep')
170+
endif
171+
endfor
172+
163173
let &cpo= s:keepcpo
164174
unlet s:keepcpo
165175

runtime/colors/lists/default.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
" time the highlight command fails to recognize a gui color. You can override
77
" these colors by introducing a new colors/lists/default.vim file earlier in
88
" the runtimepath.
9+
" Note: the color names should be in lower case, because Vim will lookup the
10+
" a color by its lower case name.
911

1012
" make sure line continuation works
1113
let s:keepcpo = &cpo
@@ -802,6 +804,14 @@ call extend(v:colornames, {
802804
\ 'teal': '#008080'
803805
\ }, 'keep')
804806

807+
" all keys should be in lower case, convert keys that are not yet
808+
for [key, val] in items(filter(copy(v:colornames), { key -> key =~ '\u'}))
809+
call remove(v:colornames, key)
810+
if !has_key(v:colornames, tolower(key))
811+
call extend(v:colornames, {tolower(key): val}, 'keep')
812+
endif
813+
endfor
814+
805815
let &cpo = s:keepcpo
806816
unlet s:keepcpo
807817

runtime/doc/eval.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 9.1. Last change: 2024 Jan 14
1+
*eval.txt* For Vim version 9.1. Last change: 2024 Feb 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2005,9 +2005,14 @@ v:collate The current locale setting for collation order of the runtime
20052005
*v:colornames*
20062006
v:colornames A dictionary that maps color names to hex color strings. These
20072007
color names can be used with the |highlight-guifg|,
2008-
|highlight-guibg|, and |highlight-guisp| parameters. Updating
2009-
an entry in v:colornames has no immediate effect on the syntax
2010-
highlighting. The highlight commands (probably in a
2008+
|highlight-guibg|, and |highlight-guisp| parameters.
2009+
2010+
The key values in the dictionary (the color names) should be
2011+
lower cased, because Vim looks up a color by its lower case
2012+
name.
2013+
2014+
Updating an entry in v:colornames has no immediate effect on
2015+
the syntax highlighting. The highlight commands (probably in a
20112016
colorscheme script) need to be re-evaluated in order to use
20122017
the updated color values. For example: >
20132018

runtime/doc/syntax.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 9.1. Last change: 2024 Jan 24
1+
*syntax.txt* For Vim version 9.1. Last change: 2024 Feb 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -5265,7 +5265,8 @@ ctermul={color-nr} *highlight-ctermul*
52655265
"cterm=" argument AFTER the "ctermfg=" or "ctermbg=" argument. Or use
52665266
a number instead of a color name.
52675267

5268-
The case of the color names is ignored.
5268+
The case of the color names is ignored, however Vim will use lower
5269+
case color names when reading from the |v:colornames| dictionary.
52695270
Note that for 16 color ansi style terminals (including xterms), the
52705271
numbers in the NR-8 column is used. Here '*' means 'add 8' so that
52715272
Blue is 12, DarkGray is 8 etc.
@@ -5384,8 +5385,8 @@ guisp={color-name} *highlight-guisp*
53845385
:highlight Comment guifg=#11f0c3 guibg=#ff00ff
53855386
<
53865387
If you are authoring a color scheme and use the same hexadecimal value
5387-
repeatedly, you can define a name for it in |v:colornames|. For
5388-
example: >
5388+
repeatedly, you can define a (lower case) name for it in |v:colornames|.
5389+
For example: >
53895390
53905391
# provide a default value for this color but allow the user to
53915392
# override it.

0 commit comments

Comments
 (0)