From 4aa9d8841452a1001fa9c75f83c017abdd5eecad Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sat, 13 Jan 2018 07:17:02 -0600 Subject: [PATCH] .vimrc: Smartly pick AirlineTheme for certain colorscheme's --- .../plugin/airlinetheme-map.vim | 49 +++++++++++++++++++ .vimrc | 16 +++++- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 .vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim diff --git a/.vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim b/.vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim new file mode 100644 index 0000000..132111a --- /dev/null +++ b/.vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim @@ -0,0 +1,49 @@ +" Customize which :AirlineTheme to use for specific colorscheme's based on +" caller-supplied mapping table. + +" ------------------------------------------------------------------------- +" CONFIGURATION: +" +" * Dict providing the mapping table of colorscheme -> airline theme +" overrides > +" let g:colorscheme_airlinetheme_map = { ... } +" +" * Default airline theme to use when no specific entry found in the +" mapping table [and no airline theme which exactly matches current +" colorscheme] > +" let g:colorscheme_airlinetheme_default = [str] +" ------------------------------------------------------------------------- + +" Use a ColorScheme autocmd to automatically switch :AirlineTheme based on +" the new colorscheme. Defer adding the ColorScheme autocmd until the +" VimEnter event so that our ColorScheme autocmd hook will be 'last' in the +" 'autocmd ColorScheme' stack. +augroup airlinetheme_map_afterinit + autocmd! + autocmd VimEnter * silent! call on_init() +augroup END + +function! s:on_init() + augroup airlinetheme_map + autocmd! + autocmd ColorScheme * call on_colorscheme_change() + augroup END + call on_colorscheme_change() +endfunction + +function! s:on_colorscheme_change() + " if there's an AirlineTheme override for this colorscheme, use that + if exists('g:colorscheme_airlinetheme_map') && + \ has_key(g:colorscheme_airlinetheme_map, g:colors_name) + let g:airline_theme=g:colorscheme_airlinetheme_map[g:colors_name] + :AirlineRefresh + else + " if there's an exact-match AirlineTheme for the current colorscheme, + " use that; else use the user-defined default AirlineTheme (if any) + if exists('g:colorscheme_airlinetheme_default') && + \ g:airline_theme != g:colors_name + let g:airline_theme=g:colorscheme_airlinetheme_default + :AirlineRefresh + endif + endif +endfunction diff --git a/.vimrc b/.vimrc index bac407e..d3084a9 100644 --- a/.vimrc +++ b/.vimrc @@ -51,6 +51,7 @@ Plug '~/.vim/bundle/mumps' " filetype=mumps " Other Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers Plug 'tpope/vim-scriptease' " misc collection of helper commands +Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's Plug '~/.vim/bundle/autofolds' " folds for my *rc files call plug#end() @@ -190,12 +191,23 @@ if &t_Co > 2 || has("gui_running") endif augroup END + " colorscheme theme options let g:solarized_termcolors=&t_Co " use 256 colors for solarized let g:solarized_termtrans=1 - colorscheme solarized - let g:airline_theme='solarized16' " vim-airline theme + if !exists('s:set_colorscheme') + colorscheme solarized + let s:set_colorscheme=1 + endif + + " airline theme options let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme + let g:colorscheme_airlinetheme_map = { + \ 'seoul256-light': 'zenburn', + \ 'solarized': 'solarized16', + \ } + let g:colorscheme_airlinetheme_default = 'distinguished' + endif " ---------------------------------------------------------------------------- -- 2.45.2