Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I find myself often switching between dark/light colorschemes when I'm working inside/outside. However, this is a quite annoying task, I have to change the colorscheme of my terminal, and of Vim. Besides, I have multiple Vim sessions running in various tmux/terminal tabs, so when I switch to a different tab, I have to change the colorscheme of Vim again.

Then when I go inside/outside again I have to switch it all back. Quite a hassle. Has anyone found any trick to automate this? For starters I wouldn't know how to change the colorscheme of all my Vim sessions. Can you send a signal to your Vim sessions maybe? Then changing the terminal colorscheme is of course dependent on the terminal app you're using.



I use solarized, which has a light and a dark variant. So even when I'm in the terminal (which is always) I can easily switch between light and dark.

The solarized vim plugin even has a key binding to do this.


I’m just inverting the screen (built-in accessibility feature in OS X, there probably are alternatives on other platforms). Vim and the terminal are set to a light scheme, one of the standard ones. When I switch to terminal screen and it’s low light, I hit a key combo and it inverts everything. Does the job for me.


I do this, too, and it works very well. Specifically, almost everything on my screen is very light-colored (exception: when I am recreating rather than working) and then when I am working at night I use OS X to "invert" all the colors on the screen, with the result that the color 0x000000 becomes 0xFFFFFF, 0x000001 becomes 0xFFFFFE, etc.

If you have access to an OS X environment, you can try out "invert colors" at System Preferences > Accessibility > Display. iOS has it, too.


Yep! Also when I don’t want colored output (e.g. when working on familiar codebases or often in the shell), I turn on the Grayscale option in addition to inverted colors. That gives the screen cool retro-futuristic feel, and IMO makes it more aesthetically pleasing. Too bad a shortcut can’t be assigned to this one, but typing "pref access" in Spotlight gets the relevant settings page.

As a related tip, on iOS you can have a home button triple-press shortcut which you can assign inverted colors or grayscale, or both. Was stoked when discovered that.


Don't set the colorscheme on Vim, set it on your terminal and Vim will honor it. I do that with iTerm2.


But you'll have to restart the terminal for that, right?


Yup! I'm in the same boat as you - need to switch between light and dark theme due to the switch between outdoor/indoor. I run xterm in openbox, with specific placements (geometry setting) for a specific xterm window session. I ended up writing a script to place the xterm windows exactly where I want them so that I don't have to worry about restarting xterm windows and losing the spatial context. It's a hairy perl script that started life about 8 years ago I think. I have two openbox menu configured to start my xterm windows - one for black and one for white background. It also sets an environment variable there so that vim knows what colorscheme to use when it starts. So everytime I switch between indoor/outdoor I do a ":mksession!|quit", followed by alt+f4 to close the xterm window and then hit the openbox menu to reopen the just closed xterm window with the new background color, and resume my vim session with the color scheme adapted to the current background color. I bet using a modern IDE you can get this done with just one or two keystroke heh.


Nice to hear someone is having the same problem as me :). Your solution sounds nice, you still have to restart things but you kind of automated that part. Maybe I'll end up doing the same, for now I'll try to explore more possibilities. For example, `help remote.txt` could help.


Well, you can use this and not restart the terminal https://github.com/sos4nt/dynamic-colors


Thanks, will check it out!


Use a modern terminal?


Using a more modern terminal won't make vim magically change it's color scheme.


Nothing magical about it, but yes it will.

Or rather, vim doesn't need to change its color scheme in order to be displayed in a completely different set of colors, which is what he's talking about. If you change the color mapping of your terminal and vim doesn't immediately reflect that, then your terminal is not applying those changes to that window/tab.


Fair enough, I just tried it out and it indeed works, I was a bit ignorant ;).

I'll see if this will work out for me. Don't know what any pitfalls could be by setting the color scheme in the terminal. At least it's annoying if you use different terminals on different systems, you'll have to configure them separately, you can't put it in your dotfiles repos or something. Thanks anyway, will look into it!


I keep my terminal's settings in my dotfiles repo... It opens by default in what I've set as the default. I can change on a case by case basis if I want.


It does for me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: