Skip to content

Instantly share code, notes, and snippets.

@rvighne
Created June 14, 2025 15:26
Show Gist options
  • Save rvighne/526f10a4f7432233fcb5a3d919bcdb5e to your computer and use it in GitHub Desktop.
Save rvighne/526f10a4f7432233fcb5a3d919bcdb5e to your computer and use it in GitHub Desktop.
function s:AppsUseLightTheme()
silent let l:output = system('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme')
silent let l:match = matchlist(l:output, '\s\+AppsUseLightTheme\s\+REG_DWORD\s\+\(\S\+\)')
return str2nr(l:match[1], 16)
endfunction
function s:SyncBackground()
if s:AppsUseLightTheme()
set background=light
else
set background=dark
endif
endfunction
" FocusGained would be much nicer UX but it fires constantly for some reason
autocmd myvimrc GUIEnter * call s:SyncBackground()
autocmd myvimrc FocusLost * call s:SyncBackground()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment