From c88cb8805f683eb6d886743f3e147a3ab0fbee91 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 14:52:07 +1300 Subject: Move Vim background detection logic into plugin --- vim/autoload/detect_background.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 vim/autoload/detect_background.vim (limited to 'vim/autoload/detect_background.vim') diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim new file mode 100644 index 00000000..a1a2c208 --- /dev/null +++ b/vim/autoload/detect_background.vim @@ -0,0 +1,18 @@ +" 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. +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 -- cgit v1.2.3 From 562c9ce6fbbd6fc8b9c5e470121dcc8e731de21e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:39:23 +1300 Subject: Use same comment boilerplate for custom plugins A brief explanation, an author name, and the license should do fine. --- vim/autoload/detect_background.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'vim/autoload/detect_background.vim') diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim index a1a2c208..89e5d19e 100644 --- a/vim/autoload/detect_background.vim +++ b/vim/autoload/detect_background.vim @@ -1,5 +1,11 @@ -" 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. +" +" 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 +" License: Same as Vim itself +" function! detect_background#DetectBackground() " Split up the value of $COLORFGBG (if any) by semicolons -- cgit v1.2.3