aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/detect_background.vim
blob: 168640c31fe75a79f7623afcce4832eec830455e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"
" detect_background.vim: Invert Vim's built-in logic for choosing dark or
" light backgrounds; we'll default to choosing a dark background unless we
" find some reason *not* to.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
if exists('g:loaded_detect_background')
      \ || &compatible
  finish
endif
let g:loaded_detect_background = 1

" Declare autoload function for 'background' set
function! detect_background#DetectBackground()

  " Split up the value of $COLORFGBG (if any) by semicolons
  let l:colorfgbg = split($COLORFGBG, ';')

  " Get the background color value, or an empty string if none
  let l:bg = len(l:colorfgbg)
        \ ? l:colorfgbg[-1]
        \ : ''

  " Choose the background setting based on this value
  if l:bg ==# 'default'
        \ || l:bg ==# '7'
        \ || l:bg ==# '15'
      set background=light
  else
      set background=dark
  endif

endfunction