spectro.vim 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. " Vim color file
  2. " Maintainer: Pierre-Antoine Lacaze <pa.lacaze@gmail.com>
  3. " Last Change:
  4. " License: GPLv2
  5. " To install, copy to ~/.vim/colors directory. Then :colorscheme spectro
  6. " spectro is a colorscheme that lets you define the global saturation and
  7. " the global lightness to be used for all the colors. The hue is then
  8. " defined on a per color basis
  9. " hue, saturation and lightness shall be set between 0 and 255
  10. " I shamelessly used inkscape colors algorithm for HSL -> RGB conversion
  11. " The main interest is the ability to adapt to different screens
  12. " by only changing the saturation and lightness in your vimrc :
  13. " let g:spectro_saturation = 120
  14. " let g:spectro_lightness = 160
  15. set background=dark
  16. hi clear
  17. if exists("syntax_on")
  18. syntax reset
  19. endif
  20. let g:colors_name="spectro"
  21. " default saturation value
  22. if ! exists("g:spectro_saturation")
  23. let g:spectro_saturation = 130
  24. else
  25. if g:spectro_saturation > 255
  26. let g:spectro_saturation = 255
  27. elseif g:spectro_saturation < 0
  28. let g:spectro_saturation = 0
  29. endif
  30. endif
  31. " default lightness value
  32. if ! exists("g:spectro_lightness")
  33. let g:spectro_lightness = 130
  34. else
  35. if g:spectro_lightness > 255
  36. let g:spectro_lightness = 255
  37. elseif g:spectro_lightness < 0
  38. let g:spectro_lightness = 0
  39. endif
  40. endif
  41. " function returning the hexadecimal value of an integer between 0 and 16
  42. fun! Dec2hex(s)
  43. let str = "0123456789ABCDEF"
  44. return str[a:s]
  45. endfunc
  46. " function converting a (R,G,B) triplet into a "#rrggbb" string
  47. fun! FormatRGB(rgb)
  48. let r1 = a:rgb[0] / 16
  49. let g1 = a:rgb[1] / 16
  50. let b1 = a:rgb[2] / 16
  51. let r2 = a:rgb[0] % 16
  52. let g2 = a:rgb[1] % 16
  53. let b2 = a:rgb[2] % 16
  54. return "#".Dec2hex(r1).Dec2hex(r2).Dec2hex(g1).Dec2hex(g2).Dec2hex(b1).Dec2hex(b2)
  55. endfun
  56. " function converting hue to RGB
  57. fun! Hue2rgb(v1,v2,H)
  58. let v1 = a:v1
  59. let v2 = a:v2
  60. let H = a:H
  61. if H < 0
  62. let H += 6 * 255
  63. elseif H > 6 * 255
  64. let H -= 6 * 255
  65. end
  66. if H < 255
  67. return (v1 * 255 + (v2 - v1) * H) / (255 * 255)
  68. elseif H < 3 * 255
  69. return v2 / 255
  70. elseif H < 4 * 255
  71. return (v1 * 255 + (v2 - v1) * (4 * 255 - H)) / (255 * 255)
  72. else
  73. return v1 / 255
  74. endif
  75. endfun
  76. " function converting a (H,S,L) triplet into a (R,G,B) triplet
  77. fun! Hsl2rgb(h)
  78. let H = a:h
  79. let S = g:spectro_saturation
  80. let L = g:spectro_lightness
  81. if S == 0
  82. let RGB = [L,L,L]
  83. else
  84. let RGB = [0,0,0]
  85. if L < 128
  86. let v2 = L * (255 + S)
  87. else
  88. let v2 = 255* (L + S) - L * S
  89. endif
  90. let v1 = 2 * 255 * L - v2
  91. let RGB[0] = Hue2rgb(v1,v2,H * 6 + 2 * 255)
  92. let RGB[1] = Hue2rgb(v1,v2,H * 6)
  93. let RGB[2] = Hue2rgb(v1,v2,H * 6 - 2 * 255)
  94. endif
  95. return FormatRGB(RGB)
  96. endfun
  97. " we choose the hue for each color to be used
  98. " You may want to use inkscape to calibrate this
  99. let white = "#ffffff"
  100. let black = "#000000"
  101. let gray = "#dcdccc"
  102. let dblue = "#006060"
  103. let c_comm = Hsl2rgb(71)
  104. let c_spec = Hsl2rgb(27)
  105. let c_numb = Hsl2rgb(128)
  106. let c_iden = Hsl2rgb(42)
  107. let c_stat = Hsl2rgb(212)
  108. let c_prep = Hsl2rgb(8)
  109. let c_erro = Hsl2rgb(0)
  110. let c_curs = Hsl2rgb(58)
  111. let c_visu = Hsl2rgb(223)
  112. let c_tabl = Hsl2rgb(140)
  113. " let's define colors
  114. exe "hi Comment guifg=".c_comm
  115. exe "hi Special guifg=".c_spec." gui=none"
  116. exe "hi Constant guifg=".c_spec." gui=bold"
  117. exe "hi Number guifg=".c_numb
  118. exe "hi Identifier guifg=".c_iden
  119. exe "hi Statement guifg=".c_stat." gui=bold"
  120. exe "hi PreProc guifg=".c_prep." gui=bold"
  121. exe "hi Type guifg=".c_iden." gui=none"
  122. exe "hi Todo guifg=".black ." guibg=".c_iden." gui=none"
  123. exe "hi ErrorMsg guifg=".white ." guibg=".c_erro." gui=bold"
  124. exe "hi MoreMsg guifg=".white ." guibg=".c_spec." gui=bold"
  125. exe "hi Cursor guifg=".black ." guibg=".c_curs." gui=bold"
  126. exe "hi WildMenu guifg=".black ." guibg=".c_curs." gui=bold"
  127. exe "hi LineNr guifg=".c_curs
  128. exe "hi Normal guifg=".gray ." guibg=".black
  129. exe "hi Visual guifg=".black ." guibg=".c_spec
  130. exe "hi Underlined guifg=".gray ." gui=underline"
  131. exe "hi VertSplit guifg=".dblue ." guibg=".gray
  132. exe "hi TabLine guifg=".gray ." guibg=".dblue ." gui=none"
  133. exe "hi TablineFill guifg=".black ." guibg=".black
  134. exe "hi TablineSel guifg=".white ." guibg=".c_tabl." gui=none"
  135. exe "hi User2 guifg=".white ." guibg=".c_tabl." gui=none"
  136. exe "hi StatusLine guifg=".white ." guibg=".c_tabl." gui=none"
  137. exe "hi StatusLineNC guifg=".gray ." guibg=".dblue ." gui=none"
  138. exe "hi Pmenu guifg=".gray ." guibg=".dblue ." gui=none"
  139. exe "hi PmenuSel guifg=".black ." guibg=".c_tabl." gui=bold"
  140. exe "hi PmenuSbar guifg=".black ." guibg=".gray ." gui=none"
  141. exe "hi PmenuThumb guifg=".black ." guibg=".gray ." gui=none"
  142. exe "hi Directory guifg=".c_comm
  143. exe "hi DiffAdded guifg=".c_comm." gui=none"
  144. exe "hi DiffChanged guifg=".c_iden." gui=none"
  145. exe "hi DiffRemoved guifg=".c_erro." gui=none"
  146. exe "hi DiffLine guifg=".c_numb." gui=bold"
  147. exe "hi Folded guifg=".c_numb
  148. hi link SpecialChar Special
  149. hi link Tag Special
  150. hi link Delimiter Special
  151. hi link String Special
  152. hi link Character Special
  153. hi link SpecialKey Special
  154. hi link cFormat Special
  155. hi link cSpecialCharacter Special
  156. hi link Debug Constant
  157. hi link SpecialComment Constant
  158. hi link Boolean Number
  159. hi link Float Number
  160. hi link NonText Number
  161. hi link Function Identifier
  162. hi link Title Identifier
  163. hi link Conditional Statement
  164. hi link Repeat Statement
  165. hi link Label Statement
  166. hi link Operator Statement
  167. hi link keyword Statement
  168. hi link Exception Statement
  169. hi link Include PreProc
  170. hi link Define PreProc
  171. hi link Macro PreProc
  172. hi link PreCondit PreProc
  173. hi link ModeMsg PreProc
  174. hi link StorageClass Type
  175. hi link Structure Type
  176. hi link Typedef Type
  177. hi link Search Todo
  178. hi link IncSearch Todo
  179. hi link Error ErrorMsg
  180. hi link WarningMsg MoreMsg
  181. hi link Question LineNr
  182. hi link StatusLineNC TabLine
  183. hi link User2 TabLineSel
  184. hi link DiffAdd DiffAdded
  185. hi link DiffChange DiffChanged
  186. hi link DiffDelete DiffRemoved
  187. hi link DiffText DiffLine
  188. hi link FoldColumn Folded