Vim:根据一天中的时间设置颜色/主题
我有一台超级光滑的显示器,所以白天我可以比黑暗主题上的代码更好地看到自己的倒影。因此,我认为如果我可以在 vimrc 中有一个简单的 if
开关来根据一天中的时间设置深色主题或浅色主题,那就太好了。
唉,我对 vimrc 语法了解不够,谷歌搜索也不够。
有人想尝试一下吗?
I have one of those super glossy monitors, so during the day I can see my own reflection better than my code on Dark themes. So I thought it'd be great if I could have a simple if
switch in my vimrc to set either a dark theme or a light theme based on the time of day.
Alas, I don't know enough about vimrc syntax and googling came up short.
Anyone wanna take a crack at this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
像下面这样的事情应该可以解决问题:
显然你应该根据你的需要选择时间
Something like the following should do the trick:
Obviously you should choose the hour based on your needs
尝试 werewolf.vim 插件:
如果您经常使用不同的配色方案,可以设置多对浅色/深色配色方案,它会自动切换到匹配的方案。
Try the werewolf.vim plugin:
If you use often different color schemes, you can set several pairs of light/dark color schemes, and it will automatically switch to the matching scheme.
这不是严格意义上的 Vim 答案,但你可以尝试安装 f.lux 来调整你的显示器颜色一天中的时间。
这是演示。它在白天发出温暖的黄色光芒,在夜间发出蓝色光芒。
免责声明:我自己没有尝试过(但我很想尝试)。
This is not strictly a Vim answer but you could try to install f.lux which adjusts your monitor colours to the time of the day.
Here is a demo. It has a warm yellowish glow during the day, and blueish one during the night.
Disclaimer : I have not tried it myself (but I am tempted).
我知道这是一个老问题,有一个已接受的答案,但如果您希望使用 lua 而不是 vimscript 来实现相同的功能,以下是我如何实现的。
请注意,此答案假设您的首选配色方案支持
浅色
和深色
背景。I understand that this is now an old question with an accepted answer, but if you are looking to achieve the same functionality using
lua
instead ofvimscript
, here is how I accomplished it.Note that this answer assumes that your preferred color scheme supports
light
anddark
backgrounds.您可以在 vimrc 中获取 .vimrc.local。然后您可以使用 cron 根据一天中的时间覆盖该文件。没有脚本:-)
You can source a .vimrc.local in your vimrc. Then you could use cron to overwrite that file according to the time of day. no scripting :-)
我的 night-and-day 插件是一个“vim 主题调度程序”。您可以将一天划分为任意数量的间隔,并为每个间隔分配一个主题。如果在新的时间间隔开始时打开 vim,主题将自动更改。
My night-and-day plugin is a "vim theme scheduler". You can divide the day into any number of intervals and assign a theme to each. Themes will automatically change if vim is open when a new interval begins.
我已经找到了另一种改变颜色和背景的方法,
使用除法的其余部分可以更好地控制我想要改变背景的时间。我们可以使用这个 shell 循环来看看为什么:
如果我使用像 <14 这样的东西,而不是除法的其余部分,会发生什么,在午夜之后我的配色方案更改为“浅色”。所以我把剩下的时间除以6进行比较。
I have figured out another way of changing color and background
Using the rest of division gives more control over the time I want to change background. We can use this shell loop to see why:
If I use something like <14, instead of the rest of the division, what happens is that after midnight my color scheme changes to "light". So I make the comparison of the rest of the division of the hour by 6.