wombat256.vim 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. " Vim color file
  2. " Maintainer: David Liang (bmdavll at gmail dot com)
  3. " Last Change: November 28 2008
  4. "
  5. " wombat256.vim - a modified version of Wombat by Lars Nielsen that also
  6. " works on xterms with 88 or 256 colors. The algorithm for approximating the
  7. " GUI colors with the xterm palette is from desert256.vim by Henry So Jr.
  8. set background=dark
  9. if version > 580
  10. hi clear
  11. if exists("syntax_on")
  12. syntax reset
  13. endif
  14. endif
  15. let g:colors_name = "wombat256"
  16. if !has("gui_running") && &t_Co != 88 && &t_Co != 256
  17. finish
  18. endif
  19. " functions {{{
  20. " returns an approximate grey index for the given grey level
  21. fun <SID>grey_number(x)
  22. if &t_Co == 88
  23. if a:x < 23
  24. return 0
  25. elseif a:x < 69
  26. return 1
  27. elseif a:x < 103
  28. return 2
  29. elseif a:x < 127
  30. return 3
  31. elseif a:x < 150
  32. return 4
  33. elseif a:x < 173
  34. return 5
  35. elseif a:x < 196
  36. return 6
  37. elseif a:x < 219
  38. return 7
  39. elseif a:x < 243
  40. return 8
  41. else
  42. return 9
  43. endif
  44. else
  45. if a:x < 14
  46. return 0
  47. else
  48. let l:n = (a:x - 8) / 10
  49. let l:m = (a:x - 8) % 10
  50. if l:m < 5
  51. return l:n
  52. else
  53. return l:n + 1
  54. endif
  55. endif
  56. endif
  57. endfun
  58. " returns the actual grey level represented by the grey index
  59. fun <SID>grey_level(n)
  60. if &t_Co == 88
  61. if a:n == 0
  62. return 0
  63. elseif a:n == 1
  64. return 46
  65. elseif a:n == 2
  66. return 92
  67. elseif a:n == 3
  68. return 115
  69. elseif a:n == 4
  70. return 139
  71. elseif a:n == 5
  72. return 162
  73. elseif a:n == 6
  74. return 185
  75. elseif a:n == 7
  76. return 208
  77. elseif a:n == 8
  78. return 231
  79. else
  80. return 255
  81. endif
  82. else
  83. if a:n == 0
  84. return 0
  85. else
  86. return 8 + (a:n * 10)
  87. endif
  88. endif
  89. endfun
  90. " returns the palette index for the given grey index
  91. fun <SID>grey_color(n)
  92. if &t_Co == 88
  93. if a:n == 0
  94. return 16
  95. elseif a:n == 9
  96. return 79
  97. else
  98. return 79 + a:n
  99. endif
  100. else
  101. if a:n == 0
  102. return 16
  103. elseif a:n == 25
  104. return 231
  105. else
  106. return 231 + a:n
  107. endif
  108. endif
  109. endfun
  110. " returns an approximate color index for the given color level
  111. fun <SID>rgb_number(x)
  112. if &t_Co == 88
  113. if a:x < 69
  114. return 0
  115. elseif a:x < 172
  116. return 1
  117. elseif a:x < 230
  118. return 2
  119. else
  120. return 3
  121. endif
  122. else
  123. if a:x < 75
  124. return 0
  125. else
  126. let l:n = (a:x - 55) / 40
  127. let l:m = (a:x - 55) % 40
  128. if l:m < 20
  129. return l:n
  130. else
  131. return l:n + 1
  132. endif
  133. endif
  134. endif
  135. endfun
  136. " returns the actual color level for the given color index
  137. fun <SID>rgb_level(n)
  138. if &t_Co == 88
  139. if a:n == 0
  140. return 0
  141. elseif a:n == 1
  142. return 139
  143. elseif a:n == 2
  144. return 205
  145. else
  146. return 255
  147. endif
  148. else
  149. if a:n == 0
  150. return 0
  151. else
  152. return 55 + (a:n * 40)
  153. endif
  154. endif
  155. endfun
  156. " returns the palette index for the given R/G/B color indices
  157. fun <SID>rgb_color(x, y, z)
  158. if &t_Co == 88
  159. return 16 + (a:x * 16) + (a:y * 4) + a:z
  160. else
  161. return 16 + (a:x * 36) + (a:y * 6) + a:z
  162. endif
  163. endfun
  164. " returns the palette index to approximate the given R/G/B color levels
  165. fun <SID>color(r, g, b)
  166. " get the closest grey
  167. let l:gx = <SID>grey_number(a:r)
  168. let l:gy = <SID>grey_number(a:g)
  169. let l:gz = <SID>grey_number(a:b)
  170. " get the closest color
  171. let l:x = <SID>rgb_number(a:r)
  172. let l:y = <SID>rgb_number(a:g)
  173. let l:z = <SID>rgb_number(a:b)
  174. if l:gx == l:gy && l:gy == l:gz
  175. " there are two possibilities
  176. let l:dgr = <SID>grey_level(l:gx) - a:r
  177. let l:dgg = <SID>grey_level(l:gy) - a:g
  178. let l:dgb = <SID>grey_level(l:gz) - a:b
  179. let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
  180. let l:dr = <SID>rgb_level(l:gx) - a:r
  181. let l:dg = <SID>rgb_level(l:gy) - a:g
  182. let l:db = <SID>rgb_level(l:gz) - a:b
  183. let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
  184. if l:dgrey < l:drgb
  185. " use the grey
  186. return <SID>grey_color(l:gx)
  187. else
  188. " use the color
  189. return <SID>rgb_color(l:x, l:y, l:z)
  190. endif
  191. else
  192. " only one possibility
  193. return <SID>rgb_color(l:x, l:y, l:z)
  194. endif
  195. endfun
  196. " returns the palette index to approximate the 'rrggbb' hex string
  197. fun <SID>rgb(rgb)
  198. let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
  199. let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
  200. let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
  201. return <SID>color(l:r, l:g, l:b)
  202. endfun
  203. " sets the highlighting for the given group
  204. fun <SID>X(group, fg, bg, attr)
  205. if a:fg != ""
  206. exec "hi ".a:group." guifg=#".a:fg." ctermfg=".<SID>rgb(a:fg)
  207. endif
  208. if a:bg != ""
  209. exec "hi ".a:group." guibg=#".a:bg." ctermbg=".<SID>rgb(a:bg)
  210. endif
  211. if a:attr != ""
  212. if a:attr == 'italic'
  213. exec "hi ".a:group." gui=".a:attr." cterm=none"
  214. else
  215. exec "hi ".a:group." gui=".a:attr." cterm=".a:attr
  216. endif
  217. endif
  218. endfun
  219. " }}}
  220. call <SID>X("Normal", "cccccc", "242424", "none")
  221. call <SID>X("Cursor", "222222", "ecee90", "none")
  222. call <SID>X("CursorLine", "", "32322e", "none")
  223. call <SID>X("CursorColumn", "", "2d2d2d", "")
  224. "CursorIM
  225. "Question
  226. "IncSearch
  227. call <SID>X("Search", "444444", "af87d7", "")
  228. call <SID>X("MatchParen", "ecee90", "857b6f", "bold")
  229. call <SID>X("SpecialKey", "6c6c6c", "2d2d2d", "none")
  230. call <SID>X("Visual", "ecee90", "597418", "none")
  231. call <SID>X("LineNr", "857b6f", "121212", "none")
  232. call <SID>X("Folded", "a0a8b0", "404048", "none")
  233. call <SID>X("Title", "f6f3e8", "", "bold")
  234. call <SID>X("VertSplit", "444444", "444444", "none")
  235. call <SID>X("StatusLine", "f6f3e8", "444444", "italic")
  236. call <SID>X("StatusLineNC", "857b6f", "444444", "none")
  237. "Scrollbar
  238. "Tooltip
  239. "Menu
  240. "WildMenu
  241. call <SID>X("Pmenu", "f6f3e8", "444444", "")
  242. call <SID>X("PmenuSel", "121212", "caeb82", "")
  243. call <SID>X("WarningMsg", "ff0000", "", "")
  244. "ErrorMsg
  245. "ModeMsg
  246. "MoreMsg
  247. "Directory
  248. "DiffAdd
  249. "DiffChange
  250. "DiffDelete
  251. "DiffText
  252. " syntax highlighting
  253. call <SID>X("Number", "e5786d", "", "none")
  254. call <SID>X("Constant", "e5786d", "", "none")
  255. call <SID>X("String", "95e454", "", "italic")
  256. call <SID>X("Comment", "c0bc6c", "", "italic")
  257. call <SID>X("Identifier", "caeb82", "", "none")
  258. call <SID>X("Keyword", "87afff", "", "none")
  259. call <SID>X("Statement", "87afff", "", "none")
  260. call <SID>X("Function", "caeb82", "", "none")
  261. call <SID>X("PreProc", "e5786d", "", "none")
  262. call <SID>X("Type", "caeb82", "", "none")
  263. call <SID>X("Special", "ffdead", "", "none")
  264. call <SID>X("Todo", "857b6f", "", "italic")
  265. "Underlined
  266. "Error
  267. "Ignore
  268. hi! link VisualNOS Visual
  269. hi! link NonText LineNr
  270. hi! link FoldColumn Folded
  271. " delete functions {{{
  272. delf <SID>X
  273. delf <SID>rgb
  274. delf <SID>color
  275. delf <SID>rgb_color
  276. delf <SID>rgb_level
  277. delf <SID>rgb_number
  278. delf <SID>grey_color
  279. delf <SID>grey_level
  280. delf <SID>grey_number
  281. " }}}
  282. " vim:set ts=4 sw=4 noet fdm=marker: