twilight256.vim 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. " twilight256 color scheme file
  2. " Maintainer: Neal Milstein - neal dot milstein at gmail dot com
  3. " Last Change: 2011 Feb 1
  4. "
  5. " This theme copies the colors from the TextMate theme Twilight.
  6. "
  7. " The theme is designed to be used on a black background. I only tested it
  8. " using a 256-color terminal; I do not think it will work on much else (gvim,
  9. " 8-color terminal, etc.).
  10. "
  11. " The functions in this theme that convert hex color codes to the nearest
  12. " xterm-256 color number are from the theme desert2 (desert256), developed by Henry So, Jr.
  13. "
  14. " The colors of this theme are based on the TextMate Twilight theme
  15. " – www.macromates.com
  16. set background=dark
  17. if version > 580
  18. " no guarantees for version 5.8 and below, but this makes it stop
  19. " complaining
  20. hi clear
  21. if exists("syntax_on")
  22. syntax reset
  23. endif
  24. endif
  25. let g:colors_name="twilight256"
  26. if has("gui_running") || &t_Co == 88 || &t_Co == 256
  27. " functions {{{
  28. " returns an approximate grey index for the given grey level
  29. fun <SID>grey_number(x)
  30. if &t_Co == 88
  31. if a:x < 23
  32. return 0
  33. elseif a:x < 69
  34. return 1
  35. elseif a:x < 103
  36. return 2
  37. elseif a:x < 127
  38. return 3
  39. elseif a:x < 150
  40. return 4
  41. elseif a:x < 173
  42. return 5
  43. elseif a:x < 196
  44. return 6
  45. elseif a:x < 219
  46. return 7
  47. elseif a:x < 243
  48. return 8
  49. else
  50. return 9
  51. endif
  52. else
  53. if a:x < 14
  54. return 0
  55. else
  56. let l:n = (a:x - 8) / 10
  57. let l:m = (a:x - 8) % 10
  58. if l:m < 5
  59. return l:n
  60. else
  61. return l:n + 1
  62. endif
  63. endif
  64. endif
  65. endfun
  66. " returns the actual grey level represented by the grey index
  67. fun <SID>grey_level(n)
  68. if &t_Co == 88
  69. if a:n == 0
  70. return 0
  71. elseif a:n == 1
  72. return 46
  73. elseif a:n == 2
  74. return 92
  75. elseif a:n == 3
  76. return 115
  77. elseif a:n == 4
  78. return 139
  79. elseif a:n == 5
  80. return 162
  81. elseif a:n == 6
  82. return 185
  83. elseif a:n == 7
  84. return 208
  85. elseif a:n == 8
  86. return 231
  87. else
  88. return 255
  89. endif
  90. else
  91. if a:n == 0
  92. return 0
  93. else
  94. return 8 + (a:n * 10)
  95. endif
  96. endif
  97. endfun
  98. " returns the palette index for the given grey index
  99. fun <SID>grey_color(n)
  100. if &t_Co == 88
  101. if a:n == 0
  102. return 16
  103. elseif a:n == 9
  104. return 79
  105. else
  106. return 79 + a:n
  107. endif
  108. else
  109. if a:n == 0
  110. return 16
  111. elseif a:n == 25
  112. return 231
  113. else
  114. return 231 + a:n
  115. endif
  116. endif
  117. endfun
  118. " returns an approximate color index for the given color level
  119. fun <SID>rgb_number(x)
  120. if &t_Co == 88
  121. if a:x < 69
  122. return 0
  123. elseif a:x < 172
  124. return 1
  125. elseif a:x < 230
  126. return 2
  127. else
  128. return 3
  129. endif
  130. else
  131. if a:x < 75
  132. return 0
  133. else
  134. let l:n = (a:x - 55) / 40
  135. let l:m = (a:x - 55) % 40
  136. if l:m < 20
  137. return l:n
  138. else
  139. return l:n + 1
  140. endif
  141. endif
  142. endif
  143. endfun
  144. " returns the actual color level for the given color index
  145. fun <SID>rgb_level(n)
  146. if &t_Co == 88
  147. if a:n == 0
  148. return 0
  149. elseif a:n == 1
  150. return 139
  151. elseif a:n == 2
  152. return 205
  153. else
  154. return 255
  155. endif
  156. else
  157. if a:n == 0
  158. return 0
  159. else
  160. return 55 + (a:n * 40)
  161. endif
  162. endif
  163. endfun
  164. " returns the palette index for the given R/G/B color indices
  165. fun <SID>rgb_color(x, y, z)
  166. if &t_Co == 88
  167. return 16 + (a:x * 16) + (a:y * 4) + a:z
  168. else
  169. return 16 + (a:x * 36) + (a:y * 6) + a:z
  170. endif
  171. endfun
  172. " returns the palette index to approximate the given R/G/B color levels
  173. fun <SID>color(r, g, b)
  174. " get the closest grey
  175. let l:gx = <SID>grey_number(a:r)
  176. let l:gy = <SID>grey_number(a:g)
  177. let l:gz = <SID>grey_number(a:b)
  178. " get the closest color
  179. let l:x = <SID>rgb_number(a:r)
  180. let l:y = <SID>rgb_number(a:g)
  181. let l:z = <SID>rgb_number(a:b)
  182. if l:gx == l:gy && l:gy == l:gz
  183. " there are two possibilities
  184. let l:dgr = <SID>grey_level(l:gx) - a:r
  185. let l:dgg = <SID>grey_level(l:gy) - a:g
  186. let l:dgb = <SID>grey_level(l:gz) - a:b
  187. let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
  188. let l:dr = <SID>rgb_level(l:gx) - a:r
  189. let l:dg = <SID>rgb_level(l:gy) - a:g
  190. let l:db = <SID>rgb_level(l:gz) - a:b
  191. let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
  192. if l:dgrey < l:drgb
  193. " use the grey
  194. return <SID>grey_color(l:gx)
  195. else
  196. " use the color
  197. return <SID>rgb_color(l:x, l:y, l:z)
  198. endif
  199. else
  200. " only one possibility
  201. return <SID>rgb_color(l:x, l:y, l:z)
  202. endif
  203. endfun
  204. " returns the palette index to approximate the 'rrggbb' hex string
  205. fun <SID>rgb(rgb)
  206. let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
  207. let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
  208. let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
  209. return <SID>color(l:r, l:g, l:b)
  210. endfun
  211. " sets the highlighting for the given group
  212. fun <SID>X(group, fg, bg, attr)
  213. if a:fg != ""
  214. exec "hi " . a:group . " guifg=#" . a:fg . " ctermfg=" . <SID>rgb(a:fg)
  215. endif
  216. if a:bg != ""
  217. exec "hi " . a:group . " guibg=#" . a:bg . " ctermbg=" . <SID>rgb(a:bg)
  218. endif
  219. if a:attr != ""
  220. exec "hi " . a:group . " gui=" . a:attr . " cterm=" . a:attr
  221. endif
  222. endfun
  223. " }}}
  224. call <SID>X("Normal", "ffffff", "", "")
  225. " highlight groups
  226. "call <SID>X("Cursor", "708090", "f0e68c", "")
  227. "CursorIM
  228. "Directory
  229. "DiffAdd
  230. "DiffChange
  231. "DiffDelete
  232. "DiffText
  233. "ErrorMsg
  234. "call <SID>X("VertSplit", "c2bfa5", "7f7f7f", "reverse")
  235. "call <SID>X("Folded", "ffd700", "4d4d4d", "")
  236. "call <SID>X("FoldColumn", "d2b48c", "4d4d4d", "")
  237. "call <SID>X("IncSearch", "708090", "f0e68c", "")
  238. call <SID>X("LineNr", "CCCCCC", "", "")
  239. "call <SID>X("ModeMsg", "D4D4D4", "", "")
  240. "call <SID>X("MoreMsg", "2e8b57", "", "")
  241. "call <SID>X("NonText", "addbe7", "000000", "bold")
  242. "call <SID>X("Question", "00ff7f", "", "")
  243. "call <SID>X("Search", "f5deb3", "cd853f", "")
  244. "call <SID>X("SpecialKey", "9acd32", "", "")
  245. "call <SID>X("StatusLine", "c2bfa5", "000000", "reverse")
  246. "call <SID>X("StatusLineNC", "c2bfa5", "7f7f7f", "reverse")
  247. "call <SID>X("Title", "cd5c5c", "", "")
  248. call <SID>X("Visual", "D3D3D3", "3E3E3E", "reverse")
  249. "VisualNOS
  250. "call <SID>X("WarningMsg", "fa8072", "", "")
  251. "WildMenu
  252. "Menu
  253. "Scrollbar
  254. "Tooltip
  255. " syntax highlighting groups
  256. call <SID>X("Comment", "828282", "", "")
  257. call <SID>X("Constant", "CF6A4C", "", "")
  258. call <SID>X("Identifier", "7587A6", "", "none")
  259. call <SID>X("Function", "9B703F", "", "")
  260. call <SID>X("Define", "CDA869", "", "none")
  261. call <SID>X("Statement", "CDA869", "", "")
  262. call <SID>X("String", "8F9D6A", "", "")
  263. call <SID>X("PreProc", "AFC4DB", "", "")
  264. call <SID>X("Type", "F9EE98", "", "")
  265. call <SID>X("Special", "DAEFA3", "", "")
  266. "Underlined
  267. call <SID>X("Ignore", "666666", "", "")
  268. "Error
  269. call <SID>X("Todo", "ff4500", "eeee00", "")
  270. " delete functions {{{
  271. delf <SID>X
  272. delf <SID>rgb
  273. delf <SID>color
  274. delf <SID>rgb_color
  275. delf <SID>rgb_level
  276. delf <SID>rgb_number
  277. delf <SID>grey_color
  278. delf <SID>grey_level
  279. delf <SID>grey_number
  280. " }}}
  281. endif
  282. " vim: set fdl=0 fdm=marker: