用来演示 gvim 预定义颜色项的脚本
<本文的原始位置: http://bluegene8210.is-programmer.com/posts/26169.html>
---- 原来贴在 vim-cn 群里的一个脚本,这里也贴一下。
---- gvim 有好几百种预定义的颜色名称,比如 'DarkBlue', 'LightRed' 之类。这个脚本用来展示这些颜色在你的 gvim 里看起来如何。
---- 纯 VimScript 写的。用 gvim 打开脚本,然后
:source %
就可以了。
---- 会开启一个叫 'ShowVimColors.tmp' 的临时 buffer 用作显示,是 “纯” buffer 没有磁盘文件。内容分两部分,前一部分展示颜色本身,后一部分展示与黑白两色的搭配效果。
自己定义语法项要分配颜色的时候,可以用作参考。
---- 如果想搞 DIY 自己配色,记得 依云 在她的 blog 里写过一个 gvim 调色板,在 这里。也可以自己先写出来,比如 '#aabbcc',加进这个脚本里再运行一遍就能看见效果。
1 "======================================================================================================================== 2 "======= ShowVimColors.vim 3 "======================================================================================================================== 4 "======= 作者:Jacky Liu 5 "======= bluegene8210@gmail.com 6 "======================================================================================================================== 7 8 " 网上找到的 Vim 里的预定义颜色 9 let s:VimColors=[ 10 \ 'Snow', 'GhostWhite', 'WhiteSmoke', 'Gainsboro', 'FloralWhite', 'OldLace', 'Linen', 11 \ 'AntiqueWhite', 'PapayaWhip', 'BlanchedAlmond', 'Bisque', 'PeachPuff', 'NavajoWhite', 'Azure', 12 \ 'Moccasin', 'Cornsilk', 'Ivory', 'LemonChiffon', 'Seashell', 'Honeydew', 'MintCream', 13 \ 'AliceBlue', 'Lavender', 'LavenderBlush', 'MistyRose', 'White', 'Black', 'DarkSlateGray', 14 \ 'DimGray', 'SlateGray', 'LightSlateGray', 'Gray', 'LightGray', 'MidnightBlue', 'Navy', 15 \ 'NavyBlue', 'CornflowerBlue', 'DarkSlateBlue', 'SlateBlue', 'MediumSlateBlue', 16 \ 'LightSlateBlue', 'MediumBlue', 'RoyalBlue', 'Blue', 'DodgerBlue', 'DeepSkyBlue', 17 \ 'SkyBlue', 'LightSkyBlue', 'SteelBlue', 'LightSteelBlue', 'LightBlue', 'PowderBlue', 18 \ 'PaleTurquoise', 'DarkTurquoise', 'MediumTurquoise', 'Turquoise', 'Cyan', 'LightCyan', 19 \ 'CadetBlue', 'MediumAquamarine', 'Aquamarine', 'DarkGreen', 'DarkOliveGreen', 20 \ 'DarkSeaGreen', 'SeaGreen', 'MediumSeaGreen', 'LightSeaGreen', 'PaleGreen', 21 \ 'SpringGreen', 'LawnGreen', 'Green', 'Chartreuse', 'MediumSpringGreen', 'GreenYellow', 22 \ 'LimeGreen', 'YellowGreen', 'ForestGreen', 'OliveDrab', 'DarkKhaki', 'Khaki', 23 \ 'PaleGoldenrod', 'LightGoldenrodYellow', 'LightYellow', 'Yellow', 'Gold', 24 \ 'LightGoldenrod', 'Goldenrod', 'DarkGoldenrod', 'RosyBrown', 'IndianRed', 'SaddleBrown', 25 \ 'Sienna', 'Peru', 'Burlywood', 'Beige', 'Wheat', 'SandyBrown', 'Tan', 'Chocolate', 'Firebrick', 26 \ 'Brown', 'DarkSalmon', 'Salmon', 'LightSalmon', 'Orange', 'DarkOrange', 'Coral', 'LightCoral', 27 \ 'Tomato', 'OrangeRed', 'Red', 'HotPink', 'DeepPink', 'Pink', 'LightPink', 'PaleVioletRed', 28 \ 'Maroon', 'MediumVioletRed', 'VioletRed', 'Magenta', 'Violet', 'Plum', 'Orchid', 29 \ 'MediumOrchid', 'DarkOrchid', 'DarkViolet', 'BlueViolet', 'Purple', 'MediumPurple', 30 \ 'Thistle', 'Snow1', 'Snow2', 'Snow3', 'Snow4', 'Seashell1', 'Seashell2', 'Seashell3', 31 \ 'Seashell4', 'AntiqueWhite1', 'AntiqueWhite2', 'AntiqueWhite3', 'AntiqueWhite4', 32 \ 'Bisque1', 'Bisque2', 'Bisque3', 'Bisque4', 'PeachPuff1', 'PeachPuff2', 'PeachPuff3', 33 \ 'PeachPuff4', 'NavajoWhite1', 'NavajoWhite2', 'NavajoWhite3', 'NavajoWhite4', 34 \ 'LemonChiffon1', 'LemonChiffon2', 'LemonChiffon3', 'LemonChiffon4', 'Cornsilk1', 35 \ 'Cornsilk2', 'Cornsilk3', 'Cornsilk4', 'Ivory1', 'Ivory2', 'Ivory3', 'Ivory4', 'Honeydew1', 36 \ 'Honeydew2', 'Honeydew3', 'Honeydew4', 'LavenderBlush1', 'LavenderBlush2', 37 \ 'LavenderBlush3', 'LavenderBlush4', 'MistyRose1', 'MistyRose2', 'MistyRose3', 38 \ 'MistyRose4', 'Azure1', 'Azure2', 'Azure3', 'Azure4', 'SlateBlue1', 'SlateBlue2', 39 \ 'SlateBlue3', 'SlateBlue4', 'RoyalBlue1', 'RoyalBlue2', 'RoyalBlue3', 'RoyalBlue4', 40 \ 'Blue1', 'Blue2', 'Blue3', 'Blue4', 'DodgerBlue1', 'DodgerBlue2', 'DodgerBlue3', 41 \ 'DodgerBlue4', 'SteelBlue1', 'SteelBlue2', 'SteelBlue3', 'SteelBlue4', 'DeepSkyBlue1', 42 \ 'DeepSkyBlue2', 'DeepSkyBlue3', 'DeepSkyBlue4', 'SkyBlue1', 'SkyBlue2', 'SkyBlue3', 43 \ 'SkyBlue4', 'LightSkyBlue1', 'LightSkyBlue2', 'LightSkyBlue3', 'LightSkyBlue4', 44 \ 'SlateGray1', 'SlateGray2', 'SlateGray3', 'SlateGray4', 'LightSteelBlue1', 45 \ 'LightSteelBlue2', 'LightSteelBlue3', 'LightSteelBlue4', 'LightBlue1', 'LightBlue2', 46 \ 'LightBlue3', 'LightBlue4', 'LightCyan1', 'LightCyan2', 'LightCyan3', 'LightCyan4', 47 \ 'PaleTurquoise1', 'PaleTurquoise2', 'PaleTurquoise3', 'PaleTurquoise4', 'CadetBlue1', 48 \ 'CadetBlue2', 'CadetBlue3', 'CadetBlue4', 'Turquoise1', 'Turquoise2', 'Turquoise3', 49 \ 'Turquoise4', 'Cyan1', 'Cyan2', 'Cyan3', 'Cyan4', 'DarkSlateGray1', 'DarkSlateGray2', 50 \ 'DarkSlateGray3', 'DarkSlateGray4', 'Aquamarine1', 'Aquamarine2', 'Aquamarine3', 51 \ 'Aquamarine4', 'DarkSeaGreen1', 'DarkSeaGreen2', 'DarkSeaGreen3', 'DarkSeaGreen4', 52 \ 'SeaGreen1', 'SeaGreen2', 'SeaGreen3', 'SeaGreen4', 'PaleGreen1', 'PaleGreen2', 53 \ 'PaleGreen3', 'PaleGreen4', 'SpringGreen1', 'SpringGreen2', 'SpringGreen3', 54 \ 'SpringGreen4', 'Green1', 'Green2', 'Green3', 'Green4', 'Chartreuse1', 'Chartreuse2', 55 \ 'Chartreuse3', 'Chartreuse4', 'OliveDrab1', 'OliveDrab2', 'OliveDrab3', 'OliveDrab4', 56 \ 'DarkOliveGreen1', 'DarkOliveGreen2', 'DarkOliveGreen3', 'DarkOliveGreen4', 'Khaki1', 57 \ 'Khaki2', 'Khaki3', 'Khaki4', 'LightGoldenrod1', 'LightGoldenrod2', 'LightGoldenrod3', 58 \ 'LightGoldenrod4', 'LightYellow1', 'LightYellow2', 'LightYellow3', 'LightYellow4', 59 \ 'Yellow1', 'Yellow2', 'Yellow3', 'Yellow4', 'Gold1', 'Gold2', 'Gold3', 'Gold4', 'Goldenrod1', 60 \ 'Goldenrod2', 'Goldenrod3', 'Goldenrod4', 'DarkGoldenrod1', 'DarkGoldenrod2', 61 \ 'DarkGoldenrod3', 'DarkGoldenrod4', 'RosyBrown1', 'RosyBrown2', 'RosyBrown3', 62 \ 'RosyBrown4', 'IndianRed1', 'IndianRed2', 'IndianRed3', 'IndianRed4', 'Sienna1', 'Sienna2', 63 \ 'Sienna3', 'Sienna4', 'Burlywood1', 'Burlywood2', 'Burlywood3', 'Burlywood4', 'Wheat1', 64 \ 'Wheat2', 'Wheat3', 'Wheat4', 'Tan1', 'Tan2', 'Tan3', 'Tan4', 'Chocolate1', 'Chocolate2', 65 \ 'Chocolate3', 'Chocolate4', 'Firebrick1', 'Firebrick2', 'Firebrick3', 'Firebrick4', 66 \ 'Brown1', 'Brown2', 'Brown3', 'Brown4', 'Salmon1', 'Salmon2', 'Salmon3', 'Salmon4', 67 \ 'LightSalmon1', 'LightSalmon2', 'LightSalmon3', 'LightSalmon4', 'Orange1', 'Orange2', 68 \ 'Orange3', 'Orange4', 'DarkOrange1', 'DarkOrange2', 'DarkOrange3', 'DarkOrange4', 'Coral1', 69 \ 'Coral2', 'Coral3', 'Coral4', 'Tomato1', 'Tomato2', 'Tomato3', 'Tomato4', 'OrangeRed1', 70 \ 'OrangeRed2', 'OrangeRed3', 'OrangeRed4', 'Red1', 'Red2', 'Red3', 'Red4', 'DeepPink1', 71 \ 'DeepPink2', 'DeepPink3', 'DeepPink4', 'HotPink1', 'HotPink2', 'HotPink3', 'HotPink4', 72 \ 'Pink1', 'Pink2', 'Pink3', 'Pink4', 'LightPink1', 'LightPink2', 'LightPink3', 'LightPink4', 73 \ 'PaleVioletRed1', 'PaleVioletRed2', 'PaleVioletRed3', 'PaleVioletRed4', 'Maroon1', 74 \ 'Maroon2', 'Maroon3', 'Maroon4', 'VioletRed1', 'VioletRed2', 'VioletRed3', 'VioletRed4', 75 \ 'Magenta1', 'Magenta2', 'Magenta3', 'Magenta4', 'Orchid1', 'Orchid2', 'Orchid3', 'Orchid4', 76 \ 'Plum1', 'Plum2', 'Plum3', 'Plum4', 'MediumOrchid1', 'MediumOrchid2', 'MediumOrchid3', 77 \ 'MediumOrchid4', 'DarkOrchid1', 'DarkOrchid2', 'DarkOrchid3', 'DarkOrchid4', 'Purple1', 78 \ 'Purple2', 'Purple3', 'Purple4', 'MediumPurple1', 'MediumPurple2', 'MediumPurple3', 79 \ 'MediumPurple4', 'Thistle1', 'Thistle2', 'Thistle3', 'Thistle4', 80 \ 'DarkCyan', 'DarkMagenta', 'DarkRed', 'LightGreen', 81 \ '#132b4a', '#233b5a', '#005c70', '#031b4a', '#d0d0e0', 82 \ 'NONE'] 83 84 85 86 let s:statements= [] " 用来定义 syntax group 以及调用 matchadd() 的 VimScript 语句。 87 let s:filelines= [] " 加到临时 buffer 内的内容 88 89 call add(s:filelines, '输出的第一部分,展示颜色本身') 90 call add(s:filelines, '') 91 92 for vcolor in s:VimColors 93 call add(s:filelines, vcolor . repeat(' ', 160-len(vcolor))) 94 95 if vcolor =~ '^#' | let vcname= vcolor[1:] | else | let vcname= vcolor | endif 96 97 " syntax group container 98 "====================================================================================================================== 99 let sgcontname= vcname . '_cont' 100 call add(s:statements, 'syntax match ' . sgcontname . ' /^' . vcolor . '\> *$/') 101 102 " 指定主体,默认背景 103 "====================================================================================================================== 104 let fghigrpname= '_' . vcname . '_' . 'NONE' " hi group name (as frontground) 105 call add(s:statements, 'hi ' . fghigrpname . ' guifg=' . vcolor . ' guibg=' . 'NONE') " 定义 hi group 106 let fgsyngrpname= 'sgrp_' . fghigrpname " syntax group name (as frontground) 107 call add(s:statements, 'syntax match ' . fgsyngrpname . ' /^' . vcolor . '\>/ containedin=' . sgcontname . ' contained') " 定义 syntax group 108 call add(s:statements, 'hi link '. fgsyngrpname . ' ' . fghigrpname) " syntax group 与 hi group 联系起来 109 110 " 默认主体,指定背景 111 "====================================================================================================================== 112 let bghigrpname= '_' . 'NONE' . '_' . vcname " hi group name (as background) 113 call add(s:statements, 'hi ' . bghigrpname . ' guifg=' . 'NONE' . ' guibg=' . vcolor) " 定义 hi group 114 let bgsyngrpname= 'sgrp_' . bghigrpname " syntax group name (as background) 115 call add(s:statements, 'syntax match ' . bgsyngrpname . ' / \+/' . ' containedin=' . sgcontname . ' contained') " 同上 116 call add(s:statements, 'hi link '. bgsyngrpname . ' ' . bghigrpname) " 同上 117 118 endfor 119 120 call add(s:filelines, '') 121 call add(s:filelines, '输出的第二部分,展示作为主体色或作为背景色与黑白两色的搭配效果') 122 call add(s:filelines, '') 123 124 for vcolor in s:VimColors 125 126 if vcolor =~ '^#' | let vcname= vcolor[1:] | else | let vcname= vcolor | endif 127 128 " 指定主体,黑色背景 129 "====================================================================================================================== 130 let gname_1= '_' . vcname . '_' . 'Black' " syntax group name 131 call add(s:statements, 'hi ' . gname_1 . ' guifg=' . vcolor . ' guibg=' . 'Black') " 定义语句 132 133 let skwname= 'skw_' . gname_1 134 call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_1) 135 call add(s:statements, 'hi link ' . skwname . ' ' . gname_1) 136 137 " 黑色主体,指定背景 138 "====================================================================================================================== 139 let gname_2= '_' . 'Black' . '_' . vcname " syntax group name 140 call add(s:statements, 'hi ' . gname_2 . ' guifg=' . 'Black' . ' guibg=' . vcolor) " 定义语句 141 142 let skwname= 'skw_' . gname_2 143 call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_2) 144 call add(s:statements, 'hi link ' . skwname . ' ' . gname_2) 145 146 " 指定主体,白色背景 147 "====================================================================================================================== 148 let gname_3= '_' . vcname . '_' . 'White' " syntax group name 149 call add(s:statements, 'hi ' . gname_3 . ' guifg=' . vcolor . ' guibg=' . 'White') " 定义语句 150 151 let skwname= 'skw_' . gname_3 152 call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_3) 153 call add(s:statements, 'hi link ' . skwname . ' ' . gname_3) 154 155 " 白色主体,指定背景 156 "====================================================================================================================== 157 let gname_4= '_' . 'White' . '_' . vcname " syntax group name 158 call add(s:statements, 'hi ' . gname_4 . ' guifg=' . 'White' . ' guibg=' . vcolor) " 定义语句 159 160 let skwname= 'skw_' . gname_4 161 call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_4) 162 call add(s:statements, 'hi link ' . skwname . ' ' . gname_4) 163 164 " buffer 新加入一行 165 "====================================================================================================================== 166 let newline= gname_1 . repeat(' ', 30-len(gname_1)) . 167 \ gname_2 . repeat(' ', 30-len(gname_2)) . 168 \ gname_3 . repeat(' ', 30-len(gname_3)) . gname_4 169 call add(s:filelines, newline) 170 171 endfor 172 173 174 175 tabedit ShowVimColors.tmp " 开启临时 buffer 176 setlocal buftype=nofile " 设置 buffer 属性 177 call append(0, s:filelines) " 加入内容 178 179 for stat in s:statements " “上色” 180 exe stat 181 endfor 182 183 " autocmd BufWinLeave ShowVimColors.tmp call clearmatches() " 走之前清掉。不然 Vim 会一直很慢