Improve vim theme toggling

This commit is contained in:
Michael Campagnaro 2022-12-29 18:53:54 -05:00
parent 78fd8f6d45
commit 0227534656

35
vimrc
View File

@ -79,7 +79,7 @@ let g:quickfix_pane_height = 20
"""""""""""""" """"""""""""""
" COLORS " COLORS
"""""""""""""" """"""""""""""
let g:campo_default_bg_mode = 'dark' " Start vim with the dark theme. Set to 'light' for the light theme. let g:campo_light_dark_mode = 'dark' " Start vim with the dark theme. Set to 'light' for the light theme.
let g:campo_dark_theme = 'campo-dark-simple' "'campo-dark-blue' let g:campo_dark_theme = 'campo-dark-simple' "'campo-dark-blue'
let g:campo_light_theme = 'campo-light-simple' "'campo-light' let g:campo_light_theme = 'campo-light-simple' "'campo-light'
let g:campo_theme_use_rainbow_parens = 1 let g:campo_theme_use_rainbow_parens = 1
@ -126,7 +126,6 @@ let g:campo_directories_to_force_stripping_trailing_whitespace = []
" e.g. let g:campo_files_to_force_stripping_trailing_whitespace = ['/z/modules/test.h', '/d/build/config.h'] " e.g. let g:campo_files_to_force_stripping_trailing_whitespace = ['/z/modules/test.h', '/d/build/config.h']
let g:campo_files_to_force_stripping_trailing_whitespace = [] let g:campo_files_to_force_stripping_trailing_whitespace = []
"""""""""""""" """"""""""""""
" SEARCH " SEARCH
"""""""""""""" """"""""""""""
@ -956,7 +955,7 @@ let g:clojure_fuzzy_indent_blacklist = ['-fn$', '\v^with-%(meta|out-str|loading-
let g:rainbow_active = 1 " Always on let g:rainbow_active = 1 " Always on
let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gray', 'blue'] let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gray', 'blue']
let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray'] let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray']
let s:rainbow_theme = g:campo_default_bg_mode let s:rainbow_theme = g:campo_light_dark_mode
function! UpdateRainbowConf() function! UpdateRainbowConf()
let g:rainbow_conf = { let g:rainbow_conf = {
@ -1045,12 +1044,21 @@ set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
exec "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()" exec "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()"
exec "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()" exec "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()"
" Switch between light and dark themes. " Toggle between light and dark themes.
noremap <leader>l :call ChangeBgTheme('light', 0)<cr> noremap <leader>l :call ToggleLightDarkTheme()<cr>
noremap <leader>ll :call ChangeBgTheme('dark', 0)<cr>
function! ChangeBgTheme(bg, onlySetTheme) let s:current_light_dark_mode = g:campo_light_dark_mode
if a:bg =~ 'light'
function! ToggleLightDarkTheme()
if s:current_light_dark_mode == 'light'
call ChangeLightDarkMode('dark', 0)
else
call ChangeLightDarkMode('light', 0)
endif
endfunction
function! ChangeLightDarkMode(mode, onlySetTheme)
if a:mode == 'light'
let s:rainbow_theme = 'light' let s:rainbow_theme = 'light'
let s:theme = g:campo_light_theme let s:theme = g:campo_light_theme
exe 'colorscheme ' . s:theme exe 'colorscheme ' . s:theme
@ -1065,15 +1073,18 @@ function! ChangeBgTheme(bg, onlySetTheme)
exe 'colorscheme ' . s:theme exe 'colorscheme ' . s:theme
endif endif
let s:current_light_dark_mode = a:mode
if !a:onlySetTheme if !a:onlySetTheme
exec 'AirlineTheme' a:bg exec 'AirlineTheme' a:mode
endif endif
endfunction endfunction
if g:campo_default_bg_mode =~ 'light' " Set the intial light/dark mode.
call ChangeBgTheme('light', 1) if g:campo_light_dark_mode =~ 'light'
call ChangeLightDarkMode('light', 1)
else else
call ChangeBgTheme('dark', 1) call ChangeLightDarkMode('dark', 1)
endif endif