gruvbox.vim 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. " -----------------------------------------------------------------------------
  2. " File: gruvbox.vim
  3. " Description: Retro groove color scheme for Vim
  4. " Author: morhetz <morhetz@gmail.com>
  5. " Source: https://github.com/morhetz/gruvbox
  6. " Last Modified: 11 Oct 2013
  7. " -----------------------------------------------------------------------------
  8. " Supporting code -------------------------------------------------------------
  9. " Initialisation: {{{
  10. if version > 580
  11. hi clear
  12. if exists("syntax_on")
  13. syntax reset
  14. endif
  15. endif
  16. let g:colors_name='gruvbox'
  17. if !has('gui_running') && &t_Co != 256
  18. finish
  19. endif
  20. " }}}
  21. " Global settings: {{{
  22. if !exists('g:gruvbox_bold')
  23. let g:gruvbox_bold=1
  24. endif
  25. if !exists('g:gruvbox_italic')
  26. let g:gruvbox_italic=1
  27. endif
  28. if !exists('g:gruvbox_underline')
  29. let g:gruvbox_underline=1
  30. endif
  31. if !exists('g:gruvbox_italicize_comments')
  32. let g:gruvbox_italicize_comments=1
  33. endif
  34. if !exists('g:gruvbox_italicize_strings')
  35. let g:gruvbox_italicize_strings=0
  36. endif
  37. if !exists('g:gruvbox_termcolors')
  38. let g:gruvbox_termcolors=256
  39. endif
  40. if !exists('g:gruvbox_invert_indent_guides')
  41. let g:gruvbox_invert_indent_guides=0
  42. endif
  43. if !exists('g:gruvbox_hls_cursor')
  44. let g:gruvbox_hls_cursor='orange'
  45. endif
  46. if &background == 'light'
  47. let s:gruvbox_background='light'
  48. else
  49. let s:gruvbox_background='dark'
  50. endif
  51. " }}}
  52. " Palette: {{{
  53. let s:gb = {}
  54. if &background == 'dark'
  55. let s:gb.dark0 = ['282828', 235] " 40-40-40
  56. let s:gb.dark1 = ['3c3836', 237] " 60-56-54
  57. let s:gb.dark2 = ['504945', 239] " 80-73-69
  58. let s:gb.dark3 = ['665c54', 241] " 102-92-84
  59. let s:gb.dark4 = ['7c6f64', 243] " 124-111-100
  60. let s:gb.medium = ['928374', 245] " 146-131-116
  61. let s:gb.light0 = ['fdf4c1', 229] " 253-244-193
  62. let s:gb.light1 = ['ebdbb2', 223] " 235-219-178
  63. let s:gb.light2 = ['d5c4a1', 250] " 213-196-161
  64. let s:gb.light3 = ['bdae93', 248] " 189-174-147
  65. let s:gb.light4 = ['a89984', 246] " 168-153-132
  66. let s:gb.light4_256 = ['a89984', 246] " 168-153-132
  67. let s:gb.red = ['fb4934', 167] " 251-73-52
  68. let s:gb.green = ['b8bb26', 142] " 184-187-38
  69. let s:gb.yellow = ['fabd2f', 214] " 250-189-47
  70. let s:gb.blue = ['83a598', 109] " 131-165-152
  71. let s:gb.purple = ['d3869b', 175] " 211-134-155
  72. let s:gb.aqua = ['8ec07c', 108] " 142-192-124
  73. let s:gb.orange = ['fe8019', 208] " 254-128-25
  74. if g:gruvbox_termcolors == 16
  75. let s:gb.dark0 = ['282828', 0]
  76. let s:gb.light4 = ['a89984', 7]
  77. let s:gb.medium = ['928374', 8]
  78. let s:gb.red = ['fb4934', 9]
  79. let s:gb.green = ['b8bb26', 10]
  80. let s:gb.yellow = ['fabd2f', 11]
  81. let s:gb.blue = ['83a598', 12]
  82. let s:gb.purple = ['d3869b', 13]
  83. let s:gb.aqua = ['8ec07c', 14]
  84. let s:gb.light1 = ['ebdbb2', 15]
  85. endif
  86. else
  87. let s:gb.dark0 = ['fdf4c1', 229] " 253-244-193
  88. let s:gb.dark1 = ['ebdbb2', 223] " 235-219-178
  89. let s:gb.dark2 = ['d5c4a1', 250] " 213-196-161
  90. let s:gb.dark3 = ['bdae93', 248] " 189-174-147
  91. let s:gb.dark4 = ['a89984', 246] " 168-153-132
  92. let s:gb.medium = ['928374', 244] " 146-131-116
  93. let s:gb.light0 = ['282828', 235] " 40-40-40
  94. let s:gb.light1 = ['3c3836', 237] " 60-56-54
  95. let s:gb.light2 = ['504945', 239] " 80-73-69
  96. let s:gb.light3 = ['665c54', 241] " 102-92-84
  97. let s:gb.light4 = ['7c6f64', 243] " 124-111-100
  98. let s:gb.light4_256 = ['7c6f64', 243] " 124-111-100
  99. let s:gb.red = ['9d0006', 88] " 157-0-6
  100. let s:gb.green = ['79740e', 100] " 121-116-14
  101. let s:gb.yellow = ['b57614', 136] " 181-118-20
  102. let s:gb.blue = ['076678', 24] " 7-102-120
  103. let s:gb.purple = ['8f3f71', 96] " 143-63-113
  104. let s:gb.aqua = ['427b58', 66] " 66-123-88
  105. let s:gb.orange = ['af3a03', 130] " 175-58-3
  106. if g:gruvbox_termcolors == 16
  107. let s:gb.dark0 = ['fdf4c1', 0]
  108. let s:gb.light4 = ['7c6f64', 7]
  109. let s:gb.medium = ['928374', 8]
  110. let s:gb.red = ['9d0006', 9]
  111. let s:gb.green = ['79740e', 10]
  112. let s:gb.yellow = ['b57614', 11]
  113. let s:gb.blue = ['076678', 12]
  114. let s:gb.purple = ['8f3f71', 13]
  115. let s:gb.aqua = ['427b58', 14]
  116. let s:gb.light1 = ['3c3836', 15]
  117. endif
  118. endif
  119. " }}}
  120. " Highlighting Function: {{{
  121. function! s:HL(group, fg, ...)
  122. " Arguments: group, guifg, guibg, gui, guisp
  123. let histring = 'hi ' . a:group . ' '
  124. if strlen(a:fg)
  125. if a:fg == 'fg'
  126. let histring .= 'guifg=fg ctermfg=fg '
  127. elseif a:fg == 'bg'
  128. let histring .= 'guifg=bg ctermfg=bg '
  129. elseif a:fg == 'none'
  130. let histring .= 'guifg=NONE ctermfg=NONE '
  131. else
  132. let c = get(s:gb, a:fg)
  133. let histring .= 'guifg=#' . c[0] . ' ctermfg=' . c[1] . ' '
  134. endif
  135. endif
  136. if a:0 >= 1 && strlen(a:1)
  137. if a:1 == 'bg'
  138. let histring .= 'guibg=bg ctermbg=bg '
  139. elseif a:fg == 'fg'
  140. let histring .= 'guibg=fg ctermbg=fg '
  141. elseif a:1 == 'none'
  142. let histring .= 'guibg=NONE ctermbg=NONE '
  143. else
  144. let c = get(s:gb, a:1)
  145. let histring .= 'guibg=#' . c[0] . ' ctermbg=' . c[1] . ' '
  146. endif
  147. else
  148. let histring .= 'guibg=NONE ctermbg=NONE '
  149. endif
  150. if a:0 >= 2 && strlen(a:2)
  151. if a:2 == 'none'
  152. let histring .= 'gui=NONE cterm=NONE '
  153. elseif a:2 == 'italic' && g:gruvbox_italic == 0
  154. let histring .= 'gui=NONE cterm=NONE '
  155. elseif a:2 == 'bold' && g:gruvbox_bold == 0
  156. let histring .= 'gui=NONE cterm=NONE '
  157. elseif a:2 == 'bold,inverse' && g:gruvbox_bold == 0
  158. let histring .= 'gui=inverse cterm=inverse '
  159. elseif a:2 == 'underline' && g:gruvbox_underline == 0
  160. let histring .= 'gui=NONE cterm=NONE '
  161. elseif a:2 == 'bold,italic'
  162. if g:gruvbox_italic == 0 && g:gruvbox_bold == 0
  163. let histring .= 'gui=NONE cterm=NONE '
  164. elseif g:gruvbox_italic == 0
  165. let histring .= 'gui=bold cterm=bold '
  166. elseif g:gruvbox_bold == 0
  167. let histring .= 'gui=italic cterm=italic '
  168. else
  169. let histring .= 'gui=' . a:2 . ' cterm=' . a:2 . ' '
  170. endif
  171. else
  172. let histring .= 'gui=' . a:2 . ' cterm=' . a:2 . ' '
  173. endif
  174. else
  175. let histring .= 'gui=NONE cterm=NONE '
  176. endif
  177. if a:0 >= 3 && strlen(a:3)
  178. if a:3 == 'none'
  179. let histring .= 'guisp=NONE '
  180. else
  181. let c = get(s:gb, a:3)
  182. let histring .= 'guisp=#' . c[0] . ' '
  183. endif
  184. endif
  185. execute histring
  186. endfunction
  187. " }}}
  188. " Vanilla colorscheme ---------------------------------------------------------
  189. " General UI: {{{
  190. " Normal text
  191. call s:HL('Normal', 'light1', 'dark0')
  192. " Correct background (see issue #7):
  193. " --- Problem with changing between dark and light on 256 color terminal
  194. " --- https://github.com/morhetz/gruvbox/issues/7
  195. if s:gruvbox_background == 'light'
  196. set background=light
  197. else
  198. set background=dark
  199. endif
  200. if version >= 700
  201. " Screen line that the cursor is
  202. call s:HL('CursorLine', 'none', 'dark1')
  203. " Screen column that the cursor is
  204. call s:HL('CursorColumn', 'none', 'dark1')
  205. " Tab pages line filler
  206. call s:HL('TabLineFill', 'dark4', 'bg')
  207. " Active tab page label
  208. call s:HL('TabLineSel', 'bg', 'dark4', 'bold')
  209. " Not active tab page label
  210. call s:HL('TabLine', 'dark4', 'bg')
  211. " Match paired bracket under the cursor
  212. call s:HL('MatchParen', 'none', 'dark3', 'bold')
  213. endif
  214. if version >= 703
  215. " Highlighted screen columns
  216. call s:HL('ColorColumn', 'none', 'dark1')
  217. " Concealed element: \lambda → λ
  218. call s:HL('Conceal', 'blue', 'none')
  219. " Line number of CursorLine
  220. call s:HL('CursorLineNr', 'yellow', 'dark1')
  221. endif
  222. call s:HL('NonText', 'dark2')
  223. call s:HL('SpecialKey', 'dark2')
  224. call s:HL('Visual', 'none', 'dark3', 'inverse')
  225. call s:HL('VisualNOS', 'none', 'dark3', 'inverse')
  226. call s:HL('Search', 'dark0', 'yellow')
  227. call s:HL('IncSearch', 'dark0', 'yellow')
  228. call s:HL('Underlined', 'blue', 'none', 'underline')
  229. call s:HL('StatusLine', 'dark4', 'dark0', 'bold,inverse')
  230. call s:HL('StatusLineNC', 'dark2', 'light4', 'bold,inverse')
  231. " The column separating vertically split windows
  232. call s:HL('VertSplit', 'light4', 'dark2')
  233. " Current match in wildmenu completion
  234. call s:HL('WildMenu', 'blue', 'dark2', 'bold')
  235. " Directory names, special names in listing
  236. call s:HL('Directory', 'green', 'none', 'bold')
  237. " Titles for output from :set all, :autocmd, etc.
  238. call s:HL('Title', 'green', 'none', 'bold')
  239. " Error messages on the command line
  240. call s:HL('ErrorMsg', 'bg', 'red', 'bold')
  241. " More prompt: -- More --
  242. call s:HL('MoreMsg', 'yellow', 'none', 'bold')
  243. " Current mode message: -- INSERT --
  244. call s:HL('ModeMsg', 'yellow', 'none', 'bold')
  245. " 'Press enter' prompt and yes/no questions
  246. call s:HL('Question', 'orange', 'none', 'bold')
  247. " Warning messages
  248. call s:HL('WarningMsg', 'red', 'none', 'bold')
  249. " }}}
  250. " Gutter: {{{
  251. " Line number for :number and :# commands
  252. call s:HL('LineNr', 'dark4')
  253. " Column where signs are displayed
  254. call s:HL('SignColumn', 'none', 'bg')
  255. " Line used for closed folds
  256. call s:HL('Folded', 'medium', 'dark1', 'italic')
  257. " Column where folds are displayed
  258. call s:HL('FoldColumn', 'medium', 'dark1')
  259. " }}}
  260. " Cursor: {{{
  261. " Character under cursor
  262. call s:HL('Cursor', 'none', 'none', 'inverse')
  263. " Visual mode cursor, selection
  264. call s:HL('vCursor', 'none', 'none', 'inverse')
  265. " Input moder cursor
  266. call s:HL('iCursor', 'none', 'none', 'inverse')
  267. " Language mapping cursor
  268. call s:HL('lCursor', 'none', 'none', 'inverse')
  269. " }}}
  270. " Syntax Highlighting: {{{
  271. call s:HL('Special', 'orange')
  272. if g:gruvbox_italicize_comments == 0
  273. call s:HL('Comment', 'medium', 'none')
  274. else
  275. call s:HL('Comment', 'medium', 'none', 'italic')
  276. endif
  277. call s:HL('Todo', 'fg', 'bg', 'bold')
  278. " Generic statement
  279. call s:HL('Statement', 'red')
  280. " if, then, else, endif, swicth, etc.
  281. call s:HL('Conditional', 'red')
  282. " for, do, while, etc.
  283. call s:HL('Repeat', 'red')
  284. " case, default, etc.
  285. call s:HL('Label', 'red')
  286. " try, catch, throw
  287. call s:HL('Exception', 'red')
  288. " sizeof, "+", "*", etc.
  289. hi! def link Operator Normal
  290. " Any other keyword
  291. call s:HL('Keyword', 'red')
  292. " Variable name
  293. call s:HL('Identifier', 'blue')
  294. " Function name
  295. call s:HL('Function', 'green', 'none', 'bold')
  296. " Generic preprocessor
  297. call s:HL('PreProc', 'aqua')
  298. " Preprocessor #include
  299. call s:HL('Include', 'aqua')
  300. " Preprocessor #define
  301. call s:HL('Define', 'aqua')
  302. " Same as Define
  303. call s:HL('Macro', 'aqua')
  304. " Preprocessor #if, #else, #endif, etc.
  305. call s:HL('PreCondit', 'aqua')
  306. " Generic constant
  307. call s:HL('Constant', 'purple')
  308. " Character constant: 'c', '/n'
  309. call s:HL('Character', 'purple')
  310. " String constant: "this is a string"
  311. if g:gruvbox_italicize_strings == 0
  312. call s:HL('String', 'green')
  313. else
  314. call s:HL('String', 'green', 'none', 'italic')
  315. endif
  316. " Boolean constant: TRUE, false
  317. call s:HL('Boolean', 'purple')
  318. " Number constant: 234, 0xff
  319. call s:HL('Number', 'purple')
  320. " Floating point constant: 2.3e10
  321. call s:HL('Float', 'purple')
  322. " Generic type
  323. call s:HL('Type', 'yellow')
  324. " static, register, volatile, etc
  325. call s:HL('StorageClass', 'orange')
  326. " struct, union, enum, etc.
  327. call s:HL('Structure', 'aqua')
  328. " typedef
  329. call s:HL('Typedef', 'yellow')
  330. " }}}
  331. " Completion Menu: {{{
  332. if version >= 700
  333. " Popup menu: normal item
  334. call s:HL('Pmenu', 'light1', 'dark2')
  335. " Popup menu: selected item
  336. call s:HL('PmenuSel', 'dark2', 'blue', 'bold')
  337. " Popup menu: scrollbar
  338. call s:HL('PmenuSbar', 'none', 'dark2')
  339. " Popup menu: scrollbar thumb
  340. call s:HL('PmenuThumb', 'none', 'dark4')
  341. endif
  342. " }}}
  343. " Diffs: {{{
  344. call s:HL('DiffDelete', 'dark0', 'red')
  345. call s:HL('DiffAdd', 'dark0', 'green')
  346. "call s:HL('DiffChange', 'dark0', 'blue')
  347. "call s:HL('DiffText', 'dark0', 'yellow')
  348. " Alternative setting
  349. call s:HL('DiffChange', 'dark0', 'aqua')
  350. call s:HL('DiffText', 'dark0', 'yellow')
  351. " }}}
  352. " Spelling: {{{
  353. if has("spell")
  354. " Not capitalised word
  355. call s:HL('SpellCap', 'none', 'none', 'undercurl', 'red')
  356. " Not recognized word
  357. call s:HL('SpellBad', 'none', 'none', 'undercurl', 'blue')
  358. " Wrong spelling for selected region
  359. call s:HL('SpellLocal', 'none', 'none', 'undercurl', 'aqua')
  360. " Rare word
  361. call s:HL('SpellRare', 'none', 'none', 'undercurl', 'purple')
  362. endif
  363. " }}}
  364. " Plugin specific -------------------------------------------------------------
  365. " EasyMotion: {{{
  366. hi! def link EasyMotionTarget Search
  367. hi! def link EasyMotionShade Comment
  368. " }}}
  369. " Indent Guides: {{{
  370. let g:indent_guides_auto_colors = 0
  371. if g:gruvbox_invert_indent_guides == 0
  372. call s:HL('IndentGuidesOdd', 'bg', 'dark2')
  373. call s:HL('IndentGuidesEven', 'bg', 'dark1')
  374. else
  375. call s:HL('IndentGuidesOdd', 'bg', 'dark2', 'inverse')
  376. call s:HL('IndentGuidesEven', 'bg', 'dark3', 'inverse')
  377. endif
  378. " }}}
  379. " Better Rainbow Parentheses: {{{
  380. let g:rbpt_colorpairs = [
  381. \ ['brown', '#458588'],
  382. \ ['Darkblue', '#b16286'],
  383. \ ['darkgray', '#cc241d'],
  384. \ ['darkgreen', '#d65d0e'],
  385. \ ['darkcyan', '#458588'],
  386. \ ['darkred', '#b16286'],
  387. \ ['darkmagenta', '#cc241d'],
  388. \ ['brown', '#d65d0e'],
  389. \ ['gray', '#458588'],
  390. \ ['black', '#b16286'],
  391. \ ['darkmagenta', '#cc241d'],
  392. \ ['Darkblue', '#d65d0e'],
  393. \ ['darkgreen', '#458588'],
  394. \ ['darkcyan', '#b16286'],
  395. \ ['darkred', '#cc241d'],
  396. \ ['red', '#d65d0e'],
  397. \ ]
  398. "}}}
  399. " Filetype specific -----------------------------------------------------------
  400. " Diff: {{{
  401. call s:HL('diffAdded', 'green')
  402. call s:HL('diffRemoved', 'red')
  403. call s:HL('diffChanged', 'aqua')
  404. call s:HL('diffFile', 'orange')
  405. call s:HL('diffNewFile', 'yellow')
  406. call s:HL('diffLine', 'blue')
  407. " }}}
  408. " Html: {{{
  409. call s:HL('htmlTag', 'blue')
  410. call s:HL('htmlEndTag', 'blue')
  411. call s:HL('htmlTagName', 'aqua', 'none', 'bold')
  412. call s:HL('htmlArg', 'aqua')
  413. call s:HL('htmlScriptTag', 'purple')
  414. call s:HL('htmlTagN', 'light1')
  415. call s:HL('htmlSpecialTagName', 'aqua', 'none', 'bold')
  416. call s:HL('htmlLink', 'light4', 'none', 'underline')
  417. call s:HL('htmlSpecialChar', 'orange')
  418. " }}}
  419. " Vim: {{{
  420. if g:gruvbox_italicize_comments == 0
  421. call s:HL('vimCommentTitle', 'light4_256', 'none', 'bold')
  422. else
  423. call s:HL('vimCommentTitle', 'light4_256', 'none', 'bold,italic')
  424. endif
  425. "hi! def link vimVar Identifier
  426. "hi! def link vimFunc Function
  427. "hi! def link vimUserFunc Function
  428. "call s:HL('vimUserFunc', 'green', 'none', 'bold')
  429. "call s:HL('vimFunction', 'green', 'none', 'bold')
  430. "call s:HL('vimFunc', 'blue')
  431. "call s:HL('vimFuncName', 'blue')
  432. "call s:HL('vimVar', 'purple')
  433. "call s:HL('vimIsCommand', 'purple')
  434. "call s:HL('vimMapMod', 'purple', 'none', 'bold,italic')
  435. "call s:HL('vimMapModKey', 'purple', 'none', 'bold,italic')
  436. "call s:HL('vimFunction', 'purple')
  437. "call s:HL('vimUserFunc', 'purple')
  438. "call s:HL('vimUserFunc', 'purple')
  439. "hi! def link vimFunc Function
  440. "hi! def link vimUserFunc Function
  441. " }}}
  442. " Functions -------------------------------------------------------------------
  443. " Search Highlighting {{{
  444. "function! gruvbox#bg_toggle()
  445. " if &background == 'dark'
  446. " set bg=light
  447. " else
  448. " set bg=dark
  449. " endif
  450. "endfunction
  451. function! gruvbox#hls_show()
  452. set hlsearch
  453. call s:HL('Cursor', 'dark0', g:gruvbox_hls_cursor)
  454. call s:HL('vCursor', 'dark0', g:gruvbox_hls_cursor)
  455. call s:HL('iCursor', 'dark0', g:gruvbox_hls_cursor)
  456. call s:HL('lCursor', 'dark0', g:gruvbox_hls_cursor)
  457. endfunction
  458. function! gruvbox#hls_hide()
  459. set nohlsearch
  460. call s:HL('Cursor', 'none', 'none', 'inverse')
  461. call s:HL('vCursor', 'none', 'none', 'inverse')
  462. call s:HL('iCursor', 'none', 'none', 'inverse')
  463. call s:HL('lCursor', 'none', 'none', 'inverse')
  464. endfunction
  465. function! gruvbox#hls_toggle()
  466. if &hlsearch
  467. call gruvbox#hls_hide()
  468. else
  469. call gruvbox#hls_show()
  470. endif
  471. endfunction
  472. " }}}