aboutsummaryrefslogtreecommitdiff
path: root/vim/config/syntax.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-29 23:27:59 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-29 23:27:59 +1300
commitab104099db86661d1dcb86d58f1e318ae06dbb05 (patch)
treeb42e825dae224b0774a3239c0c049c0d1b6f355d /vim/config/syntax.vim
parentAllow and track COLORFGBG/TERM env vars in tmux (diff)
downloaddotfiles-ab104099db86661d1dcb86d58f1e318ae06dbb05.tar.gz
dotfiles-ab104099db86661d1dcb86d58f1e318ae06dbb05.zip
Switch on COLORFGBG to get background lightness
Now that this environment variable is kept and updated in tmux after 54553ae, we should be able to either configure terminals or explicitly set it during startup if we want to use lighter terminals. I'm much more comfortable with this than simply hardcoding it in the configuration. This doesn't solve the problem of carrying the environment variable over an SSH session, however, but I'm not really sure there's a solution to that besides configuring sshd(8) itself to accept these variables in transit.
Diffstat (limited to 'vim/config/syntax.vim')
-rw-r--r--vim/config/syntax.vim29
1 files changed, 26 insertions, 3 deletions
diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim
index af332ba3..250ce924 100644
--- a/vim/config/syntax.vim
+++ b/vim/config/syntax.vim
@@ -5,8 +5,31 @@ if has('syntax')
silent! syntax enable
silent! syntax sync minlines=100
- " I almost always use a dark background, so use that version of the selected
- " colorscheme
- set background=dark
+ " 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.
+ if has('eval')
+
+ " Wrap all this logic in a function
+ function! 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
+
+ " Cull the function just defined directly
+ call DetectBackground()
+
+ endif
endif