用来演示 gvim 预定义颜色项的脚本 - Jacky Liu's Blog

用来演示 gvim 预定义颜色项的脚本

Jacky Liu posted @ 2011年4月18日 07:18 in Vim with tags color vim 颜色 , 6358 阅读

    ---- 原来贴在 vim-cn 群里的一个脚本,这里也贴一下。

 

 

    ---- gvim 有好几百种预定义的颜色名称,比如 'DarkBlue', 'LightRed' 之类。这个脚本用来展示这些颜色在你的 gvim 里看起来如何。

    ---- 纯 VimScript 写的。用 gvim 打开脚本,然后
       
        :source %
   
    就可以了。

    ---- 会开启一个叫 'ShowVimColors.tmp' 的临时 buffer 用作显示,是 “纯” buffer 没有磁盘文件。内容分两部分,前一部分展示颜色本身,后一部分展示与黑白两色的搭配效果。自己定义语法项要分配颜色的时候,可以用作参考。

    ---- 如果想搞 DIY 自己配色,记得 依云 在她的 blog 里写过一个 gvim 调色板,在 这里。也可以自己先写出来,比如 '#aabbcc',加进这个脚本里再运行一遍就能看见效果。

 

"========================================================================================================================
"=======	ShowVimColors.vim
"========================================================================================================================
"=======	作者:Jacky Liu
"=======	bluegene8210@gmail.com
"========================================================================================================================

" 网上找到的 Vim 里的预定义颜色
let	s:VimColors=[
\	'Snow',			'GhostWhite',		'WhiteSmoke',		'Gainsboro',		'FloralWhite',		'OldLace',		'Linen',
\	'AntiqueWhite',		'PapayaWhip',		'BlanchedAlmond',	'Bisque',		'PeachPuff',		'NavajoWhite',		'Azure',
\	'Moccasin',		'Cornsilk',		'Ivory',		'LemonChiffon',		'Seashell',		'Honeydew',		'MintCream',
\	'AliceBlue',		'Lavender',		'LavenderBlush',	'MistyRose',		'White',		'Black',		'DarkSlateGray',
\	'DimGray',		'SlateGray',		'LightSlateGray',	'Gray',			'LightGray',		'MidnightBlue',		'Navy',
\	'NavyBlue',		'CornflowerBlue',	'DarkSlateBlue',	'SlateBlue',		'MediumSlateBlue',
\	'LightSlateBlue',	'MediumBlue',		'RoyalBlue',		'Blue',			'DodgerBlue',		'DeepSkyBlue',
\	'SkyBlue',		'LightSkyBlue',		'SteelBlue',		'LightSteelBlue',	'LightBlue',		'PowderBlue',
\	'PaleTurquoise',	'DarkTurquoise',	'MediumTurquoise',	'Turquoise',		'Cyan',			'LightCyan',
\	'CadetBlue',		'MediumAquamarine',	'Aquamarine',		'DarkGreen',		'DarkOliveGreen',
\	'DarkSeaGreen',		'SeaGreen',		'MediumSeaGreen',	'LightSeaGreen',	'PaleGreen',
\	'SpringGreen',		'LawnGreen',		'Green',		'Chartreuse',		'MediumSpringGreen',	'GreenYellow',
\	'LimeGreen',		'YellowGreen',		'ForestGreen',		'OliveDrab',		'DarkKhaki',		'Khaki',
\	'PaleGoldenrod',	'LightGoldenrodYellow',	'LightYellow',		'Yellow',		'Gold',
\	'LightGoldenrod',	'Goldenrod',		'DarkGoldenrod',	'RosyBrown',		'IndianRed',		'SaddleBrown',
\	'Sienna',		'Peru',			'Burlywood',		'Beige',		'Wheat',		'SandyBrown',		'Tan',			'Chocolate',		'Firebrick',
\	'Brown',		'DarkSalmon',		'Salmon',		'LightSalmon',		'Orange',		'DarkOrange',		'Coral',		'LightCoral',
\	'Tomato',		'OrangeRed',		'Red',			'HotPink',		'DeepPink',		'Pink',			'LightPink',		'PaleVioletRed',
\	'Maroon',		'MediumVioletRed',	'VioletRed',		'Magenta',		'Violet',		'Plum',			'Orchid',
\	'MediumOrchid',		'DarkOrchid',		'DarkViolet',		'BlueViolet',		'Purple',		'MediumPurple',
\	'Thistle',		'Snow1',		'Snow2',		'Snow3',		'Snow4',		'Seashell1',		'Seashell2',		'Seashell3',
\	'Seashell4',		'AntiqueWhite1',	'AntiqueWhite2',	'AntiqueWhite3',	'AntiqueWhite4',
\	'Bisque1',		'Bisque2',		'Bisque3',		'Bisque4',		'PeachPuff1',		'PeachPuff2',		'PeachPuff3',
\	'PeachPuff4',		'NavajoWhite1',		'NavajoWhite2',		'NavajoWhite3',		'NavajoWhite4',
\	'LemonChiffon1',	'LemonChiffon2',	'LemonChiffon3',	'LemonChiffon4',	'Cornsilk1',
\	'Cornsilk2',		'Cornsilk3',		'Cornsilk4',		'Ivory1',		'Ivory2',		'Ivory3',		'Ivory4',		'Honeydew1',
\	'Honeydew2',		'Honeydew3',		'Honeydew4',		'LavenderBlush1',	'LavenderBlush2',
\	'LavenderBlush3',	'LavenderBlush4',	'MistyRose1',		'MistyRose2',		'MistyRose3',
\	'MistyRose4',		'Azure1',		'Azure2',		'Azure3',		'Azure4',		'SlateBlue1',		'SlateBlue2',
\	'SlateBlue3',		'SlateBlue4',		'RoyalBlue1',		'RoyalBlue2',		'RoyalBlue3',		'RoyalBlue4',
\	'Blue1',		'Blue2',		'Blue3',		'Blue4',		'DodgerBlue1',		'DodgerBlue2',		'DodgerBlue3',
\	'DodgerBlue4',		'SteelBlue1',		'SteelBlue2',		'SteelBlue3',		'SteelBlue4',		'DeepSkyBlue1',
\	'DeepSkyBlue2',		'DeepSkyBlue3',		'DeepSkyBlue4',		'SkyBlue1',		'SkyBlue2',		'SkyBlue3',
\	'SkyBlue4',		'LightSkyBlue1',	'LightSkyBlue2',	'LightSkyBlue3',	'LightSkyBlue4',
\	'SlateGray1',		'SlateGray2',		'SlateGray3',		'SlateGray4',		'LightSteelBlue1',
\	'LightSteelBlue2',	'LightSteelBlue3',	'LightSteelBlue4',	'LightBlue1',		'LightBlue2',
\	'LightBlue3',		'LightBlue4',		'LightCyan1',		'LightCyan2',		'LightCyan3',		'LightCyan4',
\	'PaleTurquoise1',	'PaleTurquoise2',	'PaleTurquoise3',	'PaleTurquoise4',	'CadetBlue1',
\	'CadetBlue2',		'CadetBlue3',		'CadetBlue4',		'Turquoise1',		'Turquoise2',		'Turquoise3',
\	'Turquoise4',		'Cyan1',		'Cyan2',		'Cyan3',		'Cyan4',		'DarkSlateGray1',	'DarkSlateGray2',
\	'DarkSlateGray3',	'DarkSlateGray4',	'Aquamarine1',		'Aquamarine2',		'Aquamarine3',
\	'Aquamarine4',		'DarkSeaGreen1',	'DarkSeaGreen2',	'DarkSeaGreen3',	'DarkSeaGreen4',
\	'SeaGreen1',		'SeaGreen2',		'SeaGreen3',		'SeaGreen4',		'PaleGreen1',		'PaleGreen2',
\	'PaleGreen3',		'PaleGreen4',		'SpringGreen1',		'SpringGreen2',		'SpringGreen3',
\	'SpringGreen4',		'Green1',		'Green2',		'Green3',		'Green4',		'Chartreuse1',		'Chartreuse2',
\	'Chartreuse3',		'Chartreuse4',		'OliveDrab1',		'OliveDrab2',		'OliveDrab3',		'OliveDrab4',
\	'DarkOliveGreen1',	'DarkOliveGreen2',	'DarkOliveGreen3',	'DarkOliveGreen4',	'Khaki1',
\	'Khaki2',		'Khaki3',		'Khaki4',		'LightGoldenrod1',	'LightGoldenrod2',	'LightGoldenrod3',
\	'LightGoldenrod4',	'LightYellow1',		'LightYellow2',		'LightYellow3',		'LightYellow4',
\	'Yellow1',		'Yellow2',		'Yellow3',		'Yellow4',		'Gold1',		'Gold2',		'Gold3',		'Gold4',		'Goldenrod1',
\	'Goldenrod2',		'Goldenrod3',		'Goldenrod4',		'DarkGoldenrod1',	'DarkGoldenrod2',
\	'DarkGoldenrod3',	'DarkGoldenrod4',	'RosyBrown1',		'RosyBrown2',		'RosyBrown3',
\	'RosyBrown4',		'IndianRed1',		'IndianRed2',		'IndianRed3',		'IndianRed4',		'Sienna1',		'Sienna2',
\	'Sienna3',		'Sienna4',		'Burlywood1',		'Burlywood2',		'Burlywood3',		'Burlywood4',		'Wheat1',
\	'Wheat2',		'Wheat3',		'Wheat4',		'Tan1',			'Tan2',			'Tan3',			'Tan4',			'Chocolate1',		'Chocolate2',
\	'Chocolate3',		'Chocolate4',		'Firebrick1',		'Firebrick2',		'Firebrick3',		'Firebrick4',
\	'Brown1',		'Brown2',		'Brown3',		'Brown4',		'Salmon1',		'Salmon2',		'Salmon3',		'Salmon4',
\	'LightSalmon1',		'LightSalmon2',		'LightSalmon3',		'LightSalmon4',		'Orange1',		'Orange2',
\	'Orange3',		'Orange4',		'DarkOrange1',		'DarkOrange2',		'DarkOrange3',		'DarkOrange4',		'Coral1',
\	'Coral2',		'Coral3',		'Coral4',		'Tomato1',		'Tomato2',		'Tomato3',		'Tomato4',		'OrangeRed1',
\	'OrangeRed2',		'OrangeRed3',		'OrangeRed4',		'Red1',			'Red2',			'Red3',			'Red4',			'DeepPink1',
\	'DeepPink2',		'DeepPink3',		'DeepPink4',		'HotPink1',		'HotPink2',		'HotPink3',		'HotPink4',
\	'Pink1',		'Pink2',		'Pink3',		'Pink4',		'LightPink1',		'LightPink2',		'LightPink3',		'LightPink4',
\	'PaleVioletRed1',	'PaleVioletRed2',	'PaleVioletRed3',	'PaleVioletRed4',	'Maroon1',
\	'Maroon2',		'Maroon3',		'Maroon4',		'VioletRed1',		'VioletRed2',		'VioletRed3',		'VioletRed4',
\	'Magenta1',		'Magenta2',		'Magenta3',		'Magenta4',		'Orchid1',		'Orchid2',		'Orchid3',		'Orchid4',
\	'Plum1',		'Plum2',		'Plum3',		'Plum4',		'MediumOrchid1',	'MediumOrchid2',	'MediumOrchid3',
\	'MediumOrchid4',	'DarkOrchid1',		'DarkOrchid2',		'DarkOrchid3',		'DarkOrchid4',		'Purple1',
\	'Purple2',		'Purple3',		'Purple4',		'MediumPurple1',	'MediumPurple2',	'MediumPurple3',
\	'MediumPurple4',	'Thistle1',		'Thistle2',		'Thistle3',		'Thistle4',
\	'DarkCyan',		'DarkMagenta',		'DarkRed',		'LightGreen',
\	'#132b4a',		'#233b5a',		'#005c70',		'#031b4a',		'#d0d0e0',
\	'NONE']



let s:statements= []	" 用来定义 syntax group 以及调用 matchadd() 的 VimScript 语句。
let s:filelines= []	" 加到临时 buffer 内的内容

call add(s:filelines, '输出的第一部分,展示颜色本身')
call add(s:filelines, '')

for vcolor in s:VimColors
	call add(s:filelines, vcolor . repeat(' ', 160-len(vcolor)))
	
	if vcolor =~ '^#' | let vcname= vcolor[1:] | else | let vcname= vcolor | endif
	
	"	syntax group container
	"======================================================================================================================
	let sgcontname= vcname . '_cont'
	call add(s:statements, 'syntax match ' . sgcontname . ' /^' . vcolor . '\> *$/')

	"	指定主体,默认背景
	"======================================================================================================================
	let fghigrpname= '_' . vcname . '_' . 'NONE'			" hi group name (as frontground)
	call add(s:statements, 'hi ' . fghigrpname . ' guifg=' . vcolor . ' guibg=' . 'NONE')	" 定义 hi group
	let fgsyngrpname= 'sgrp_' . fghigrpname				" syntax group name (as frontground)
	call add(s:statements, 'syntax match ' . fgsyngrpname . ' /^' . vcolor . '\>/ containedin=' . sgcontname . ' contained')	" 定义 syntax group
	call add(s:statements, 'hi link '. fgsyngrpname . ' ' . fghigrpname)	" syntax group 与 hi group 联系起来

	"	默认主体,指定背景
	"======================================================================================================================
	let bghigrpname= '_' . 'NONE' . '_' . vcname			" hi group name (as background)
	call add(s:statements, 'hi ' . bghigrpname . ' guifg=' . 'NONE' . ' guibg=' . vcolor)	" 定义 hi group
	let bgsyngrpname= 'sgrp_' . bghigrpname				" syntax group name (as background)
	call add(s:statements, 'syntax match ' . bgsyngrpname . ' / \+/' . ' containedin=' . sgcontname . ' contained')	" 同上
	call add(s:statements, 'hi link '. bgsyngrpname . ' ' . bghigrpname)	" 同上
	
endfor

call add(s:filelines, '')
call add(s:filelines, '输出的第二部分,展示作为主体色或作为背景色与黑白两色的搭配效果')
call add(s:filelines, '')

for vcolor in s:VimColors

	if vcolor =~ '^#' | let vcname= vcolor[1:] | else | let vcname= vcolor | endif

	"	指定主体,黑色背景
	"======================================================================================================================
	let gname_1= '_' . vcname . '_' . 'Black'						" syntax group name
	call add(s:statements, 'hi	' . gname_1 . '	guifg=' . vcolor . '	guibg=' . 'Black')	" 定义语句
	
	let skwname= 'skw_' . gname_1
	call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_1)
	call add(s:statements, 'hi link ' . skwname . ' ' . gname_1)

	"	黑色主体,指定背景
	"======================================================================================================================
	let gname_2= '_' . 'Black' . '_' . vcname						" syntax group name
	call add(s:statements, 'hi	' . gname_2 . '	guifg=' . 'Black' . '	guibg=' . vcolor)	" 定义语句
	
	let skwname= 'skw_' . gname_2
	call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_2)
	call add(s:statements, 'hi link ' . skwname . ' ' . gname_2)

	"	指定主体,白色背景
	"======================================================================================================================
	let gname_3= '_' . vcname . '_' . 'White'						" syntax group name
	call add(s:statements, 'hi	' . gname_3 . '	guifg=' . vcolor . '	guibg=' . 'White')	" 定义语句
	
	let skwname= 'skw_' . gname_3
	call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_3)
	call add(s:statements, 'hi link ' . skwname . ' ' . gname_3)

	"	白色主体,指定背景
	"======================================================================================================================
	let gname_4= '_' . 'White' . '_' . vcname						" syntax group name
	call add(s:statements, 'hi	' . gname_4 . '	guifg=' . 'White' . '	guibg=' . vcolor)	" 定义语句
	
	let skwname= 'skw_' . gname_4
	call add(s:statements, 'syntax keyword ' . skwname . ' ' . gname_4)
	call add(s:statements, 'hi link ' . skwname . ' ' . gname_4)

	"	buffer 新加入一行
	"======================================================================================================================
	let newline=	gname_1 . repeat(' ', 30-len(gname_1)) .
	\		gname_2 . repeat(' ', 30-len(gname_2)) .
	\		gname_3 . repeat(' ', 30-len(gname_3)) . gname_4
	call add(s:filelines, newline)

endfor



tabedit ShowVimColors.tmp	" 开启临时 buffer
setlocal buftype=nofile		" 设置 buffer 属性
call append(0, s:filelines)	" 加入内容

for stat in s:statements	" “上色”
	exe stat
endfor

"	autocmd BufWinLeave ShowVimColors.tmp	call clearmatches()	" 走之前清掉。不然 Vim 会一直很慢



 

Avatar_small
自由建客 说:
2012年4月09日 10:28

「记得 依云 在她的 blog 里」
依云是 MM?

Avatar_small
Jacky Liu 说:
2012年4月14日 04:09

@自由建客: MM 不能玩电脑么? :-)

Avatar_small
自由建客 说:
2012年4月14日 14:17

@Jacky Liu: 不是说 MM 不能玩电脑,只是好奇。依云种种表现看起来并不像 MM 啊!求真相!

Avatar_small
MBSE +1 Model Paper 说:
2022年8月22日 02:37

This board operates under the direction of the Mizorami government, and it also oversees and manages the educational institutions to which it is associated. The Mizoram 11th Important Question Paper 2023 for the class 11th examinations will be made available via their official website. The Mizoram 11th Model Question Paper was released by this board ahead of time, and the exams for the 11th grade began on February 25 and finished on March 11. <a href="https://www.edpost.in/mbse-1-model-paper/">MBSE +1 Model Paper 2023</a> The Mizoram 11th Important Question Paper 2023 of this examination, which will be shortly announced by this board through its official website, is now being awaited by all students who took the tests.

Avatar_small
MBSE +1 Model Paper 说:
2022年8月22日 02:37

This board operates under the direction of the Mizorami government, and it also oversees and manages the educational institutions to which it is associated. The Mizoram 11th Important Question Paper 2023 for the class 11th examinations will be made available via their official website. The Mizoram 11th Model Question Paper was released by this board ahead of time, and the exams for the 11th grade began on February 25 and finished on March 11. MBSE +1 Model Paper 2023 The Mizoram 11th Important Question Paper 2023 of this examination, which will be shortly announced by this board through its official website, is now being awaited by all students who took the tests.

Avatar_small
anonymous 说:
2023年8月12日 14:20

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... Kissimmee Termite Control

Avatar_small
anonymous 说:
2023年8月21日 00:34

You ought to basically fantastic not to mention solid advice, which means notice: Orlando Bed Bug Pest Control

Avatar_small
anonymous 说:
2023年8月21日 00:37

This is helpful, nonetheless it can be crucial so that you can check out the following website: Oviedo Bed Bug Pest Control

Avatar_small
anonymous 说:
2023年9月26日 15:24

These things are very important, good think so - I think so too...  Watten House

Avatar_small
anonymous 说:
2023年9月26日 15:27

This is exciting, nevertheless it is vital for you to visit this specific url: The Continuum

Avatar_small
boardmodelpaper.com 说:
2024年1月18日 15:41

The Board model paper" typically refers to a sample or model question paper that is designed by educational boards or institutions for various exams. These papers serve as practice material for students preparing for exams, providing them with an idea of the question format, difficulty level, and the type of content that may be covered in the actual examination. boardmodelpaper.com Model papers are usually created for specific subjects or courses. They cover a range of topics and chapters that students are expected to have studied during the academic term. Students often use these educational board model papers as an integral part of their exam preparation strategy, helping them familiarize themselves with the exam pattern and refine their understanding of the subject matter.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee