aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/detect_background.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/autoload/detect_background.vim')
-rw-r--r--vim/autoload/detect_background.vim24
1 files changed, 24 insertions, 0 deletions
diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim
new file mode 100644
index 00000000..89e5d19e
--- /dev/null
+++ b/vim/autoload/detect_background.vim
@@ -0,0 +1,24 @@
+"
+" 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
+"
+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