Ⅰ. 插件描述

Vim plugin to adapt the vim theme depending on the ambient light

Ⅱ. 基本信息

创建日期:  2015-03-26
使用用户:  0
Github星:  2
插件作者:  Tom L.

Ⅲ. 安装方法


Plugin 'lleixat/ambienter-vim'
… 然后在Vim中运行以下命令:
:source %

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。


NeoBundle 'lleixat/ambienter-vim'
… 然后在Vim中运行以下命令:
:source %


Plug 'lleixat/ambienter-vim'
… 然后在Vim中运行以下命令:
:source %


cd ~/.vim/bundle
git clone

Ⅳ. 文档说明

## Introduction

  • Problem : I love dark colorshemes. Sometimes the ambient light or the laptop backlight makes uncomfortable reading and it's best to change the colorscheme.
  • Solution : My laptop have many built-in sensors included an Ambient Light Sensor (als), so I have tryed to make the switch automatic.

This plugin purpose the manual switch between a "dark" and "light" theme, or based on the light sensor detection.


Tested on GNU/Linux but should work on any *nix like system.

This plugin was fully tested and is running properly on :

  • Yoga2 Pro on Achlinux.


Use your preferred Pathogen|Bundle|NeoBundle|Vundle thing.

Vundle 'lleixat/ambienter-vim'

Additionally you can install the colorshemes used in this doc:

Vundle 'chriskempson/base16-vim'

Here is an example using Neobundle with chriskempson/base16-vim repository as dependency (optional):

NeoBundle 'lleixat/ambienter-vim', {'depends': 'chriskempson/base16-vim'}



You have to set your custom config in your vimrc, just like that:

let g:ambienter_config = {
            \     "sensor": {
            \         "path": "/sys/class/backlight/intel_backlight/actual_brightness",
            \         "value": {"min": 200 }
            \     },
            \     "theme": {
            \         "light": {
            \             "background": "light",
            \             "colorsheme": "base16-solarized"
            \         },
            \         "dark": {
            \             "background": "dark",
            \             "colorsheme": "base16-ocean"
            \         }
            \     },
            \     "callbacks": [function("airline#load_theme")]
            \ }

Using sensor ...

I use the built-in ambient light sensor (als) on my laptop (Yoga2 Pro). Here are my "sensor" values:

\ "sensor": {
\     "path": "/sys/bus/iio/devices/iio:device3/in_intensity_both_raw",
\     "value": {"min": 2000}
\ },

You must define the path accordingly to your system setup.

... or not

If you don't have any built-in light sensor, you can use your screen brightness:

\ "sensor": {
\    "path": "/sys/class/backlight/intel_backlight/actual_brightness",
\    "value": {"min": 200}
\ },

Basically, you can use any self updated file that contain a digit.

The "value.min" option define the minimum value for the switch to occur (basically from "dark" to "light").

This value is obtained after trail and error, and probably needs some adjustments to suit everyone.


You have to define your own properties for "light" and"dark" theme. Usually, the background value must be dark or light.

\ "theme": {
\     "light": {
\         "background": "light",
\         "colorsheme": "base16-solarized"
\     },
\     "dark": {
\         "background": "dark",
\         "colorsheme": "base16-ocean"
\     }
\ },

I recommend to keep the background and colorsheme definition as usual, somewhere in your vimrc:

" Set default theme
set background=dark
colorscheme base16-ocean

Callback definition

Callbacks are fired after the theme switching and are defined in an array with the g:ambienter_config.callbacks var:

let g:ambienter_config.callbacks = [function("SendPlop"), function("MyAwesomeCustomFunction")]

Callback functions are optional and must be defined before setting the "callbacks" key:

" Defining the SendPlop callback function for Ambienter
function! SendPlop()
    echom "Plop !"

" Sending a 'plop' message after theme switching
let g:ambienter_config.callbacks = [function("SendPlop")]

Fom here, you can use the predefined commands as described below.


Toggling between 'dark' and 'light' theme

:Ambienter: This command call the Switch function and allow toggling between your predefined dark and light theme. You can force the dark theme using the bang method.


Change the current theme

:AmbienterSet <ambient>: Switch to the ambient passed in parameter. The <ambient> parameter could be dark, light or hellokittyambient if you have setted the g:ambienter_config.theme.hellokittyambient value...

:AmbienterSet dark
:AmbienterSet hellokittyambient

Theme switching based on sensor value



Automagically (ie: on BufEnter and WinEnter event):

au WinEnter,BufEnter * call Ambienter.Sensor() " Adapt colorsheme to ambient light

Enjoy !

Screenshots and Links

Ambienter in action (todo)



A small debug mode is available with:

let g:ambienter_config.debug = 1


Airline won't refresh properly on au BufEnter * ... event.
Try to set this callback in g:ambienter_config:

let g:ambienter_config.callbacks = [function("airline#load_theme")]


Feel free to contribute | fork | pull-request | issue | drop me good coffee etc.