Skip to content

Instantly share code, notes, and snippets.

@spazm
Last active October 21, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spazm/42f91818768f86b123de49f7a7ef5800 to your computer and use it in GitHub Desktop.
Save spazm/42f91818768f86b123de49f7a7ef5800 to your computer and use it in GitHub Desktop.
vimrc code for setting light/dark from environment variable and zsh aliases to set the ENV
" check ITERM_PROFILE for 'DARK' or 'LIGHT' substrings, set background to match.
if $ITERM_PROFILE =~? 'DARK\c'
set background=dark
endif
if $ITERM_PROFILE =~? 'LIGHT\c'
set background=light
endif
alias light='echo "setting ITERM_PROFILE to light"; export ITERM_PROFILE="light"'
alias dark='echo "setting ITERM_PROFILE to dark"; export ITERM_PROFILE="dark"'
@spazm
Copy link
Author

spazm commented Oct 11, 2018

iterm2 exports an environment variable ITERM_PROFILE containing the (user defined) name of the profile.

Adding "Light" or "Dark" within the profile name will trigger automatic handling by the vim code above.

I don't even use iterm2 anymore, having gone back to a linux laptop. But none of the xterm derived terminals provide usable profile information. I find the light/dark commands a nice way to change if I'm stuck in a flipped terminal (like when giving presentations).

@spazm
Copy link
Author

spazm commented Oct 21, 2020

Edited .vimrc

  • correctly do case-insensitive matching whether or not that is enabled as a default.
    By adding a ? to the end of the comparator.
  • fix light check to check for substring match, rather than exact string (=~ vs == typo)

see the "LOGIC OPERATIONS" section 41.4 of the vim documentation: http://vimdoc.sourceforge.net/htmldoc/usr_41.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment