1
0
Fork 0
mirror of synced 2024-10-14 16:09:00 -04:00

Replace airline with lightline (much better perfomance)

This commit is contained in:
amix 2016-05-14 13:22:57 +01:00
parent b17bde0bae
commit 31d077d82a
191 changed files with 5349 additions and 11334 deletions

View file

@ -73,13 +73,13 @@ I recommend reading the docs of these plugins to understand them better. Each of
* [vim-indent-object](https://github.com/michaeljsmith/vim-indent-object): Defines a new text object representing lines of code at the same indent level. Useful for python/vim scripts
* [vim-multiple-cursors](https://github.com/terryma/vim-multiple-cursors): Sublime Text style multiple selections for Vim, CTRL+N is remapped to CTRL+S (due to YankRing)
* [vim-expand-region](https://github.com/terryma/vim-expand-region): Allows you to visually select increasingly larger regions of text using the same key combination.
* [vim-airline](https://github.com/bling/vim-airline): Lean & mean status/tabline for vim that's light as air (replacing powerline)
* [vim-fugitive](https://github.com/tpope/vim-fugitive): A Git wrapper so awesome, it should be illegal
* [goyo.vim](https://github.com/junegunn/goyo.vim) and [vim-zenroom2](https://github.com/amix/vim-zenroom2):
Remove all clutter and focus only on the essential. Similar to iA Writer or Write Room [Read more here](http://amix.dk/blog/post/19744)
* [vim-commentary](https://github.com/tpope/vim-commentary): Comment stuff out. Use `gcc` to comment out a line (takes a count), `gc` to comment out the target of a motion. `gcu` uncomments a set of adjacent commented lines.
* [syntastic](https://github.com/scrooloose/syntastic): Syntax checking hacks for vim
* [vim-yankstack](https://github.com/maxbrunsfeld/vim-yankstack): Maintains a history of previous yanks, changes and deletes
* [lightline.vim](https://github.com/itchyny/lightline.vim): A light and configurable statusline/tabline for Vim
## Included color schemes

View file

@ -0,0 +1 @@
/doc/tags

View file

@ -0,0 +1,22 @@
language: generic
sudo: false
install:
- git clone --depth=1 https://github.com/thinca/vim-themis /tmp/themis
- git clone https://github.com/vim/vim $HOME/vim
- (if ! test -d $HOME/vim-7.4/bin; then cd $HOME/vim && git checkout . && git checkout v7.4 && ./configure --prefix=$HOME/vim-7.4 && make && make install; fi)
- (if ! test -d $HOME/vim-7.3/bin; then cd $HOME/vim && git checkout . && git checkout v7.3 && ./configure --prefix=$HOME/vim-7.3 && make && make install; fi)
- (if ! test -d $HOME/vim-7.2.051/bin; then cd $HOME/vim && git checkout . && git checkout v7.2.051 && ./configure --prefix=$HOME/vim-7.2.051 && make && make install; fi)
cache:
directories:
- $HOME/vim-7.4
- $HOME/vim-7.3
- $HOME/vim-7.2.051
script:
- /tmp/themis/bin/themis --reporter spec
- PATH=$HOME/vim-7.4/bin/:$PATH /tmp/themis/bin/themis --reporter spec
- PATH=$HOME/vim-7.3/bin/:$PATH /tmp/themis/bin/themis --reporter spec
- PATH=$HOME/vim-7.2.051/bin/:$PATH /tmp/themis/bin/themis --reporter spec

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013-2016 itchyny
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,788 @@
# lightline.vim
A light and configurable statusline/tabline for Vim
https://github.com/itchyny/lightline.vim
### powerline theme (default)
![lightline.vim - powerline](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/powerline/0.png)
### wombat (with the patched font)
![lightline.vim - wombat](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/wombat/0.png)
### jellybeans (with the patched font)
![lightline.vim - jellybeans](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/jellybeans/0.png)
### solarized theme (dark)
![lightline.vim - solarized_dark](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/solarized_dark/0.png)
### solarized theme (light)
![lightline.vim - solarized_light](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/solarized_light/0.png)
### PaperColor theme (light)
![lightline.vim - PaperColor](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/PaperColor/0.png)
### seoul256 theme
![lightline.vim - seoul256](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/seoul256/0.png)
### landscape theme (with the patched font)
![lightline.vim - landscape](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/landscape/0.png)
With branch name, read-only mark and modified mark.
![lightline.vim - landscape - fugitive](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/landscape/5.png)
landscape is my colorscheme, which is a high-contrast cui-supported colorscheme, available at https://github.com/itchyny/landscape.vim
## Why yet another clone of powerline?
+ [vim-powerline](https://github.com/Lokaltog/vim-powerline) is a nice plugin, but deprecated.
+ [powerline](https://github.com/Lokaltog/powerline) is a nice plugin, but difficult to configure.
+ [vim-airline](https://github.com/bling/vim-airline) is a nice plugin, but it uses too much functions of other plugins, which should be done by users in `.vimrc`.
## Spirit of this plugin
+ Minimalism. The core script is very small.
+ Configurability. You can create your own component and easily add to the statusline/tabline.
+ Orthogonality. Any plugin should not change the settings of another plugin. Such plugin-crossing settings should be written by users in `.vimrc`.
## Author
itchyny (https://github.com/itchyny)
## License
This software is released under the MIT License, see LICENSE.
## Installation
### Manually
1. Put all files under $VIM.
### Pathogen
1. Install with the following command.
git clone https://github.com/itchyny/lightline.vim ~/.vim/bundle/lightline.vim
### Vundle (https://github.com/gmarik/Vundle.vim)
1. Add the following configuration to your `.vimrc`.
Plugin 'itchyny/lightline.vim'
2. Install with `:PluginInstall`.
### NeoBundle (https://github.com/Shougo/neobundle.vim)
1. Add the following configuration to your `.vimrc`.
NeoBundle 'itchyny/lightline.vim'
2. Install with `:NeoBundleInstall`.
### vim-plug (https://github.com/junegunn/vim-plug)
1. Add the following configuration to your `.vimrc`.
Plug 'itchyny/lightline.vim'
2. Install with `:PlugInstall`.
## Configuration tutorial
By default, the statusline looks like:
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/1.png)
If you use the wombat colorscheme, add the following settings to your `.vimrc` (or \_vimrc on Windows):
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ }
```
to get:
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/2.png)
If your statusline looks like
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/21.png)
and the cool statuslines appear only on `:vsp`, add
```vim
set laststatus=2
```
to your `.vimrc`.
If you have problem like
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/20.png)
then add
```sh
export TERM=xterm-256color
```
to your `.*shrc` and add
```vim
if !has('gui_running')
set t_Co=256
endif
```
to your `.vimrc`.
If the colors of the statusline do not change from the default colors, move the settings of `g:lightline` before setting the colorscheme.
If you are reloading your `.vimrc` via `autocmd` and get this problem
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/20.png)
when saving it you need to add the nested flag to your `autocmd` like so
```vim
augroup reload_vimrc
autocmd!
autocmd bufwritepost $MYVIMRC nested source $MYVIMRC
augroup END
```
Colors appear correctly? Now let's see how to change the appearance.
You may think that the default read-only mark is not so cool:
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/3.png)
Then edit the read-only component.
The lightline components are stored in `g:lightline.component`.
So you add the settings of `g:lightline.component.readonly` in your `.vimrc`. (the following settings are effective with the patched font for vim-powerline):
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'component': {
\ 'readonly': '%{&readonly?"⭤":""}',
\ }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/4.png)
How nice!
But the boundaries are quadrilateral. You may miss the powerline.
You have installed a cool font for powerlines, so you can use it.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'component': {
\ 'readonly': '%{&readonly?"⭤":""}',
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/5.png)
Hurrah! Cool!
If your statusline looks like:
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/16.png)
the patched font is not installed.
There are two kinds of patched fonts:
+ The patched fonts for [vim-powerline](https://github.com/Lokaltog/vim-powerline): see https://github.com/Lokaltog/vim-powerline/tree/develop/fontpatcher
+ The patched fonts for [powerline](https://github.com/Lokaltog/powerline): see https://github.com/Lokaltog/powerline-fonts
Create or download a font and install it.
And add the `guifont` setting to your `.vimrc` (see `:help 'guifont'` for more detail).
If you are using the vim in a terminal, the font cannot be controlled in `.vimrc`.
Open the setting of the terminal and select the patched font.
This tutorial is based on the former, the font for vim-powerline (Inconsolata for Powerline).
If you have installed the patched font for powerline, use the following settings instead.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'component': {
\ 'readonly': '%{&readonly?"":""}',
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/19.png)
If you have installed the font for powerline and your statusline looks like
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/18.png)
remove
```vim
set ambiwidth=double
```
from your `.vimrc`. If you want to keep this setting, use the patched font for vim-powerline.
+ https://github.com/Lokaltog/vim-powerline/tree/develop/fontpatcher
If you will not install a patched font, use ascii characters like:
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'component': {
\ 'readonly': '%{&readonly?"x":""}',
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '|', 'right': '|' }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/17.png)
If the triangles do not appear (but you get some spaces or weird characters like <bf> or ¿), firstly try adding
```vim
set encoding=utf-8
scriptencoding utf-8
```
to the head of your `.vimrc`.
Still you have weird characters, use the unicode numbers. For powerline font
users:
```vim
\ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
\ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" }
```
For vim-powerline font users:
```vim
\ 'separator': { 'left': "\u2b80", 'right': "\u2b82" },
\ 'subseparator': { 'left': "\u2b81", 'right': "\u2b83" }
```
Almost all of things go well with the patched font but if the triangle looks weird:
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/22.png)
If you are using iTerm2, change the following settings of iTerm2:
+ set `Profiles>Colors>Minimum contrast` to the Lowest.
+ set `Profiles>Window>Transparency` to the Opaquest.
For other terminals, this weird-triangle problem will be resolved by disabling transparency or contrast adjustment.
If you want to get rid of the extraneous default vim mode information that is now provided by lightline:
![lightline.vim - showmode](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/showmode.png)
```vim
set noshowmode
```
Now, let us get back to the tutorial (with the patched font for vim-powerline).
You look into a help file to find the marks annoying.
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/6.png)
Help files are read-only and no-modifiable? We know that!
OK, so you again edit the components.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'component': {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/7.png)
Huh? Weird!
The components do not collapse even if they have no information!
In order to avoid this situation, you set expressions to `g:lightline.component_visible_condition`, which should become 1 only when the corresponding components have information.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'component': {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))'
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/8.png)
Okay. It works nice.
How does lightline decide the components to show in the statusline?
It's very simple.
The variables to select components are `g:lightline.active.left` and `g:lightline.active.right`.
For example, you add the `g:lightline.active.left` in `.vimrc`.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component': {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))'
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
```
If the plugin arranges all the components (in a situation you `set paste` and the file `.vimrc` is read-only, try to modify):
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/9.png)
The mode component, the paste component, read-only component, filename component and modified component in a row.
Normally, the paste component does not show up.
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/10.png)
If the file is not read-only (more common cases), the read-only component does not show up.
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/11.png)
Again look into `g:lightline.active.left`.
```vim
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] ...
```
And the screen shot of all the components.
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/9.png)
The mode and paste component are displayed in the same group.
The read-only, filename and modified component are in the second group.
It corresponds to the structure of `g:lightline.active.left`.
You can configure the components in the statusline by the following four variables:
+ `g:lightline.active.left`
+ `g:lightline.active.right`
+ `g:lightline.inactive.left`
+ `g:lightline.inactive.right`
Of course, your settings in `.vimrc` have priority over the default settings in lightline.
GitHub branch is important for us.
And it is a default component in [powerline](https://github.com/Lokaltog/powerline) and [vim-powerline](https://github.com/Lokaltog/vim-powerline).
However, lightline does not provide the branch feature by default.
In order to show the branch in the statusline, you firstly install the [vim-fugitive](https://github.com/tpope/vim-fugitive) plugin.
Then edit the `g:lightline` in your `.vimrc`.
+ Add your fugitive component to `g:lightline.component`.
+ Add the condition when the fugitive component has information to `g:lightline.component_visible_condition`.
+ Add the component by inserting `'fugitive'` to `g:lightline.active.left`.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component': {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}',
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))',
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/12.png)
Okay, the branch component is added!
Now, you might get tired of setting both `'component'` and `'component_visible_condition'`.
Or if you want to do something more complicated?
In fact, the components can be created using functions.
Add your function names for components to `g:lightline.component_function`.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'fugitive': 'LightLineFugitive',
\ 'readonly': 'LightLineReadonly',
\ 'modified': 'LightLineModified'
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
function! LightLineModified()
if &filetype == "help"
return ""
elseif &modified
return "+"
elseif &modifiable
return ""
else
return ""
endif
endfunction
function! LightLineReadonly()
if &filetype == "help"
return ""
elseif &readonly
return "⭤"
else
return ""
endif
endfunction
function! LightLineFugitive()
return exists('*fugitive#head') ? fugitive#head() : ''
endfunction
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/13.png)
Fine and readable!
Finally, you come up with concatenating the three components: the read-only mark, the filename and the modified mark.
Now you may know what to do.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'filename' ] ]
\ },
\ 'component_function': {
\ 'fugitive': 'LightLineFugitive',
\ 'readonly': 'LightLineReadonly',
\ 'modified': 'LightLineModified',
\ 'filename': 'LightLineFilename'
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
function! LightLineModified()
if &filetype == "help"
return ""
elseif &modified
return "+"
elseif &modifiable
return ""
else
return ""
endif
endfunction
function! LightLineReadonly()
if &filetype == "help"
return ""
elseif &readonly
return "⭤"
else
return ""
endif
endfunction
function! LightLineFugitive()
return exists('*fugitive#head') ? fugitive#head() : ''
endfunction
function! LightLineFilename()
return ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
\ ('' != expand('%:t') ? expand('%:t') : '[No Name]') .
\ ('' != LightLineModified() ? ' ' . LightLineModified() : '')
endfunction
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/14.png)
Oops! We forgot the cool mark for the branch component! (work with the patched font for vim-powerline)
```vim
function! LightLineFugitive()
if exists("*fugitive#head")
let _ = fugitive#head()
return _ !=# '' ? '⭠ '._ : ''
endif
return ''
endfunction
```
![lightline.vim - tutorial](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/tutorial/15.png)
How cool!!!
Of course, you can name your component as you wish.
```vim
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'my_component' ] ] },
\ 'component_function': {
\ 'my_component': 'LightLineComponent', ...
```
This is the end of the tutorial. For more information, see `:help lightline`. Good luck with your nice statuslines.
### Cool characters for the patched fonts
Symbol | Default | powerline | vim-powerline
------------------ | ------- | ------------- | -------------
separator.left | '' | '' (\ue0b0) | '⮀' (\u2b80)
separator.right | '' | '' (\ue0b2) | '⮂' (\u2b82)
subseparator.left | '\|' | '' (\ue0b1) | '⮁' (\u2b81)
subseparator.right | '\|' | '' (\ue0b3) | '⮃' (\u2b83)
branch symbol | -- | '' (\ue0a0) | '⭠' (\u2b60)
readonly symbol | -- | '' (\ue0a2) | '⭤' (\u2b64)
linecolumn symbol | -- | '' (\ue0a1) | '⭡' (\u2b81)
### My settings
I show my settings. I use the patched font for vim-powerline.
```vim
let g:lightline = {
\ 'colorscheme': 'landscape',
\ 'mode_map': { 'c': 'NORMAL' },
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ] ]
\ },
\ 'component_function': {
\ 'modified': 'LightLineModified',
\ 'readonly': 'LightLineReadonly',
\ 'fugitive': 'LightLineFugitive',
\ 'filename': 'LightLineFilename',
\ 'fileformat': 'LightLineFileformat',
\ 'filetype': 'LightLineFiletype',
\ 'fileencoding': 'LightLineFileencoding',
\ 'mode': 'LightLineMode',
\ },
\ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ }
function! LightLineModified()
return &ft =~ 'help\|vimfiler\|gundo' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction
function! LightLineReadonly()
return &ft !~? 'help\|vimfiler\|gundo' && &readonly ? '⭤' : ''
endfunction
function! LightLineFilename()
return ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
\ (&ft == 'vimfiler' ? vimfiler#get_status_string() :
\ &ft == 'unite' ? unite#get_status_string() :
\ &ft == 'vimshell' ? vimshell#get_status_string() :
\ '' != expand('%:t') ? expand('%:t') : '[No Name]') .
\ ('' != LightLineModified() ? ' ' . LightLineModified() : '')
endfunction
function! LightLineFugitive()
if &ft !~? 'vimfiler\|gundo' && exists("*fugitive#head")
let _ = fugitive#head()
return _ !=# '' ? '⭠ '._ : ''
endif
return ''
endfunction
function! LightLineFileformat()
return winwidth(0) > 70 ? &fileformat : ''
endfunction
function! LightLineFiletype()
return winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : 'no ft') : ''
endfunction
function! LightLineFileencoding()
return winwidth(0) > 70 ? (&fenc !=# '' ? &fenc : &enc) : ''
endfunction
function! LightLineMode()
return winwidth(0) > 60 ? lightline#mode() : ''
endfunction
```
When the current window width is narrow, the mode component and the file information component collapse.
For example, the [gundo](https://github.com/sjl/gundo.vim) buffer is narrow.
Before:
![lightline.vim - gundo](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/gundo0.png)
After:
![lightline.vim - gundo](https://raw.githubusercontent.com/wiki/itchyny/lightline.vim/image/gundo1.png)
Nice looking, isn't it?
### For power users
For users who uses following plugins.
- [CtrlP](https://github.com/kien/ctrlp.vim)
- [Tagbar](https://github.com/majutsushi/tagbar)
- [Gundo](http://github.com/sjl/gundo.vim)
- [NERDtree](http://github.com/scrooloose/nerdtree)
- [Syntastic](https://github.com/scrooloose/syntastic)
- [unite.vim](https://github.com/Shougo/unite.vim)
- [vimfiler.vim](https://github.com/Shougo/vimfiler.vim)
- [vimshell.vim](https://github.com/Shougo/vimshell.vim)
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ], ['ctrlpmark'] ],
\ 'right': [ [ 'syntastic', 'lineinfo' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype' ] ]
\ },
\ 'component_function': {
\ 'fugitive': 'LightLineFugitive',
\ 'filename': 'LightLineFilename',
\ 'fileformat': 'LightLineFileformat',
\ 'filetype': 'LightLineFiletype',
\ 'fileencoding': 'LightLineFileencoding',
\ 'mode': 'LightLineMode',
\ 'ctrlpmark': 'CtrlPMark',
\ },
\ 'component_expand': {
\ 'syntastic': 'SyntasticStatuslineFlag',
\ },
\ 'component_type': {
\ 'syntastic': 'error',
\ },
\ 'subseparator': { 'left': '|', 'right': '|' }
\ }
function! LightLineModified()
return &ft =~ 'help' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction
function! LightLineReadonly()
return &ft !~? 'help' && &readonly ? 'RO' : ''
endfunction
function! LightLineFilename()
let fname = expand('%:t')
return fname == 'ControlP' && has_key(g:lightline, 'ctrlp_item') ? g:lightline.ctrlp_item :
\ fname == '__Tagbar__' ? g:lightline.fname :
\ fname =~ '__Gundo\|NERD_tree' ? '' :
\ &ft == 'vimfiler' ? vimfiler#get_status_string() :
\ &ft == 'unite' ? unite#get_status_string() :
\ &ft == 'vimshell' ? vimshell#get_status_string() :
\ ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
\ ('' != fname ? fname : '[No Name]') .
\ ('' != LightLineModified() ? ' ' . LightLineModified() : '')
endfunction
function! LightLineFugitive()
try
if expand('%:t') !~? 'Tagbar\|Gundo\|NERD' && &ft !~? 'vimfiler' && exists('*fugitive#head')
let mark = '' " edit here for cool mark
let _ = fugitive#head()
return _ !=# '' ? mark._ : ''
endif
catch
endtry
return ''
endfunction
function! LightLineFileformat()
return winwidth(0) > 70 ? &fileformat : ''
endfunction
function! LightLineFiletype()
return winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : 'no ft') : ''
endfunction
function! LightLineFileencoding()
return winwidth(0) > 70 ? (&fenc !=# '' ? &fenc : &enc) : ''
endfunction
function! LightLineMode()
let fname = expand('%:t')
return fname == '__Tagbar__' ? 'Tagbar' :
\ fname == 'ControlP' ? 'CtrlP' :
\ fname == '__Gundo__' ? 'Gundo' :
\ fname == '__Gundo_Preview__' ? 'Gundo Preview' :
\ fname =~ 'NERD_tree' ? 'NERDTree' :
\ &ft == 'unite' ? 'Unite' :
\ &ft == 'vimfiler' ? 'VimFiler' :
\ &ft == 'vimshell' ? 'VimShell' :
\ winwidth(0) > 60 ? lightline#mode() : ''
endfunction
function! CtrlPMark()
if expand('%:t') =~ 'ControlP' && has_key(g:lightline, 'ctrlp_item')
call lightline#link('iR'[g:lightline.ctrlp_regex])
return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
\ , g:lightline.ctrlp_next], 0)
else
return ''
endif
endfunction
let g:ctrlp_status_func = {
\ 'main': 'CtrlPStatusFunc_1',
\ 'prog': 'CtrlPStatusFunc_2',
\ }
function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
let g:lightline.ctrlp_regex = a:regex
let g:lightline.ctrlp_prev = a:prev
let g:lightline.ctrlp_item = a:item
let g:lightline.ctrlp_next = a:next
return lightline#statusline(0)
endfunction
function! CtrlPStatusFunc_2(str)
return lightline#statusline(0)
endfunction
let g:tagbar_status_func = 'TagbarStatusFunc'
function! TagbarStatusFunc(current, sort, fname, ...) abort
let g:lightline.fname = a:fname
return lightline#statusline(0)
endfunction
augroup AutoSyntastic
autocmd!
autocmd BufWritePost *.c,*.cpp call s:syntastic()
augroup END
function! s:syntastic()
SyntasticCheck
call lightline#update()
endfunction
let g:unite_force_overwrite_statusline = 0
let g:vimfiler_force_overwrite_statusline = 0
let g:vimshell_force_overwrite_statusline = 0
```
### Note for developers of other plugins
Appearance consistency matters.
The statusline is an important space for Vim users.
Overwriting the statusline forcibly in your plugin is not a good idea.
It is not hospitality, but just an annoying feature.
If your plugin has such a feature, add an option to be modest.
A good design is the following.
Firstly, give the users a clue to judge which buffer is the one your plugin creates.
The filename is a manner and the filetype is another.
Then, export a function which is useful to be shown in the statusline.
Lastly, for advanced users, set important information in buffer variables.
So that the users can obtain the condition of the plugin easily.

View file

@ -0,0 +1,485 @@
" =============================================================================
" Filename: autoload/lightline.vim
" Author: itchyny
" License: MIT License
" Last Change: 2016/05/14 13:20:45.
" =============================================================================
let s:save_cpo = &cpo
set cpo&vim
let s:_ = 1
function! lightline#update() abort
if s:_
call lightline#init()
call lightline#colorscheme()
endif
if !s:lightline.enable.statusline
return
endif
let w = winnr()
let s = winnr('$') == 1 ? [lightline#statusline(0)] : [lightline#statusline(0), lightline#statusline(1)]
for n in range(1, winnr('$'))
call setwinvar(n, '&statusline', s[n!=w])
call setwinvar(n, 'lightline', n!=w)
endfor
endfunction
function! lightline#update_once() abort
if !exists('w:lightline') || w:lightline
call lightline#update()
endif
endfunction
function! lightline#update_disable() abort
if !s:lightline.enable.statusline
return
endif
call setwinvar(0, '&statusline', '')
endfunction
function! lightline#enable() abort
call lightline#colorscheme()
call lightline#update()
if s:lightline.enable.tabline
set tabline=%!lightline#tabline()
endif
augroup lightline
autocmd!
autocmd WinEnter,BufWinEnter,FileType,ColorScheme,SessionLoadPost * call lightline#update()
autocmd ColorScheme,SessionLoadPost * call lightline#highlight()
autocmd CursorMoved,BufUnload * call lightline#update_once()
augroup END
augroup lightline-disable
autocmd!
augroup END
augroup! lightline-disable
endfunction
function! lightline#disable() abort
let [&statusline, &tabline] = [get(s:, '_statusline', ''), get(s:, '_tabline', '')]
for t in range(1, tabpagenr('$'))
for n in range(1, tabpagewinnr(t, '$'))
call settabwinvar(t, n, '&statusline', '')
endfor
endfor
augroup lightline
autocmd!
augroup END
augroup! lightline
augroup lightline-disable
autocmd!
autocmd WinEnter * call lightline#update_disable()
augroup END
endfunction
function! lightline#toggle() abort
if exists('#lightline')
call lightline#disable()
else
call lightline#enable()
endif
endfunction
let s:_lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'filename', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ], [ 'percent' ], [ 'fileformat', 'fileencoding', 'filetype' ] ]
\ },
\ 'inactive': {
\ 'left': [ [ 'filename' ] ],
\ 'right': [ [ 'lineinfo' ], [ 'percent' ] ]
\ },
\ 'tabline': {
\ 'left': [ [ 'tabs' ] ],
\ 'right': [ [ 'close' ] ]
\ },
\ 'tab': {
\ 'active': [ 'tabnum', 'filename', 'modified' ],
\ 'inactive': [ 'tabnum', 'filename', 'modified' ]
\ },
\ 'component': {
\ 'mode': '%{lightline#mode()}',
\ 'absolutepath': '%F', 'relativepath': '%f', 'filename': '%t', 'modified': '%M', 'bufnum': '%n',
\ 'paste': '%{&paste?"PASTE":""}', 'readonly': '%R', 'charvalue': '%b', 'charvaluehex': '%B',
\ 'spell': '%{&spell?&spelllang:""}', 'fileencoding': '%{&fenc!=#""?&fenc:&enc}', 'fileformat': '%{&ff}',
\ 'filetype': '%{&ft!=#""?&ft:"no ft"}', 'percent': '%3p%%', 'percentwin': '%P',
\ 'lineinfo': '%3l:%-2v', 'line': '%l', 'column': '%c', 'close': '%999X X '
\ },
\ 'component_visible_condition': {
\ 'modified': '&modified||!&modifiable', 'readonly': '&readonly', 'paste': '&paste', 'spell': '&spell'
\ },
\ 'component_function': {},
\ 'component_expand': {
\ 'tabs': 'lightline#tabs'
\ },
\ 'component_type': {
\ 'tabs': 'tabsel', 'close': 'raw'
\ },
\ 'tab_component': {},
\ 'tab_component_function': {
\ 'filename': 'lightline#tab#filename', 'modified': 'lightline#tab#modified',
\ 'readonly': 'lightline#tab#readonly', 'tabnum': 'lightline#tab#tabnum'
\ },
\ 'colorscheme': 'default',
\ 'mode_map': {
\ 'n': 'NORMAL', 'i': 'INSERT', 'R': 'REPLACE', 'v': 'VISUAL', 'V': 'V-LINE', "\<C-v>": 'V-BLOCK',
\ 'c': 'COMMAND', 's': 'SELECT', 'S': 'S-LINE', "\<C-s>": 'S-BLOCK', 't': 'TERMINAL'
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '|', 'right': '|' },
\ 'tabline_separator': {},
\ 'tabline_subseparator': {},
\ 'enable': { 'statusline': 1, 'tabline': 1 },
\ '_mode_': {
\ 'n': 'normal', 'i': 'insert', 'R': 'replace', 'v': 'visual', 'V': 'visual', "\<C-v>": 'visual',
\ 'c': 'command', 's': 'select', 'S': 'select', "\<C-s>": 'select', 't': 'terminal'
\ },
\ 'mode_fallback': { 'replace': 'insert', 'terminal': 'insert', 'select': 'visual' },
\ 'palette': {},
\ 'winwidth': winwidth(0),
\ }
function! lightline#init() abort
let s:lightline = deepcopy(get(g:, 'lightline', {}))
for [key, value] in items(s:_lightline)
if type(value) == 4
if !has_key(s:lightline, key)
let s:lightline[key] = {}
endif
call extend(s:lightline[key], value, 'keep')
elseif !has_key(s:lightline, key)
let s:lightline[key] = value
endif
unlet value
endfor
call extend(s:lightline.tabline_separator, s:lightline.separator, 'keep')
call extend(s:lightline.tabline_subseparator, s:lightline.subseparator, 'keep')
let s:lightline.tabline_configured = 0
for components in deepcopy(s:lightline.tabline.left + s:lightline.tabline.right)
if len(filter(components, 'v:val !=# "tabs" && v:val !=# "close"')) > 0
let s:lightline.tabline_configured = 1
break
endif
endfor
if !exists('s:_statusline')
let s:_statusline = &statusline
endif
if !exists('s:_tabline')
let s:_tabline = &tabline
endif
if s:lightline.enable.tabline
set tabline=%!lightline#tabline()
else
let &tabline = get(s:, '_tabline', '')
endif
for f in values(s:lightline.component_function)
silent! call call(f, [])
endfor
for f in values(s:lightline.tab_component_function)
silent! call call(f, [1])
endfor
let s:mode = ''
endfunction
function! lightline#colorscheme() abort
try
let s:lightline.palette = g:lightline#colorscheme#{s:lightline.colorscheme}#palette
catch
call lightline#error('Could not load colorscheme ' . s:lightline.colorscheme . '.')
let s:lightline.colorscheme = 'default'
let s:lightline.palette = g:lightline#colorscheme#{s:lightline.colorscheme}#palette
finally
let s:highlight = {}
call lightline#highlight('normal')
call lightline#link()
let s:_ = 0
if has('win32') && !has('gui_running') && &t_Co < 256
for u in values(s:lightline.palette)
for v in values(u)
for _ in v
let [_[2], _[3]] = [lightline#colortable#gui2cui(_[0], _[2]), lightline#colortable#gui2cui(_[1], _[3])]
endfor
endfor
endfor
endif
endtry
endfunction
function! lightline#palette() abort
return s:lightline.palette
endfunction
function! lightline#mode() abort
return get(s:lightline.mode_map, mode(), '')
endfunction
let s:mode = ''
function! lightline#link(...) abort
let mode = get(s:lightline._mode_, a:0 ? a:1 : mode(), 'normal')
if s:mode == mode
return ''
endif
let s:mode = mode
if !has_key(s:highlight, mode)
call lightline#highlight(mode)
endif
let types = map(s:uniq(sort(filter(values(s:lightline.component_type), 'v:val !=# "raw"'))), '[v:val, 1]')
for [p, l] in [['Left', len(s:lightline.active.left)], ['Right', len(s:lightline.active.right)]]
for [i, t] in map(range(0, l), '[v:val, 0]') + types
if i != l
exec printf('hi link LightLine%s_active_%s LightLine%s_%s_%s', p, i, p, mode, i)
endif
for [j, s] in map(range(0, l), '[v:val, 0]') + types
if i + 1 == j || t || s && i != l
exec printf('hi link LightLine%s_active_%s_%s LightLine%s_%s_%s_%s', p, i, j, p, mode, i, j)
endif
endfor
endfor
endfor
exec printf('hi link LightLineMiddle_active LightLineMiddle_%s', mode)
return ''
endfunction
function! s:term(p) abort
return get(a:p, 4) !=# '' ? 'term='.a:p[4].' cterm='.a:p[4].' gui='.a:p[4] : ''
endfunction
if exists('*uniq')
let s:uniq = function('uniq')
else
function! s:uniq(xs) abort
let i = len(a:xs) - 1
while i > 0
if a:xs[i] ==# a:xs[i - 1]
call remove(a:xs, i)
endif
let i -= 1
endwhile
return a:xs
endfunction
endif
function! lightline#highlight(...) abort
let [c, f] = [s:lightline.palette, s:lightline.mode_fallback]
let [s:lightline.llen, s:lightline.rlen] = [len(c.normal.left), len(c.normal.right)]
let [s:lightline.tab_llen, s:lightline.tab_rlen] = [len(has_key(get(c, 'tabline', {}), 'left') ? c.tabline.left : c.normal.left), len(has_key(get(c, 'tabline', {}), 'right') ? c.tabline.right : c.normal.right)]
let types = map(s:uniq(sort(filter(values(s:lightline.component_type), 'v:val !=# "raw"'))), '[v:val, 1]')
let modes = a:0 ? [a:1] : extend(['normal', 'insert', 'replace', 'visual', 'inactive', 'command', 'select', 'tabline'], has('nvim') ? ['terminal'] : [])
for mode in modes
let s:highlight[mode] = 1
let d = has_key(c, mode) ? mode : has_key(f, mode) && has_key(c, f[mode]) ? f[mode] : 'normal'
let left = d ==# 'tabline' ? s:lightline.tabline.left : d ==# 'inactive' ? s:lightline.inactive.left : s:lightline.active.left
let right = d ==# 'tabline' ? s:lightline.tabline.right : d ==# 'inactive' ? s:lightline.inactive.right : s:lightline.active.right
let ls = has_key(get(c, d, {}), 'left') ? c[d].left : has_key(f, d) && has_key(get(c, f[d], {}), 'left') ? c[f[d]].left : c.normal.left
let ms = has_key(get(c, d, {}), 'middle') ? c[d].middle[0] : has_key(f, d) && has_key(get(c, f[d], {}), 'middle') ? c[f[d]].middle[0] : c.normal.middle[0]
let rs = has_key(get(c, d, {}), 'right') ? c[d].right : has_key(f, d) && has_key(get(c, f[d], {}), 'right') ? c[f[d]].right : c.normal.right
for [p, l, zs] in [['Left', len(left), ls], ['Right', len(right), rs]]
for [i, t] in map(range(0, l), '[v:val, 0]') + types
if i != l
let r = t ? (has_key(get(c, d, []), i) ? c[d][i][0] : has_key(get(c, 'tabline', {}), i) ? c.tabline[i][0] : get(c.normal, i, zs)[0]) : get(zs, i, ms)
exec printf('hi LightLine%s_%s_%s guifg=%s guibg=%s ctermfg=%s ctermbg=%s %s', p, mode, i, r[0], r[1], r[2], r[3], s:term(r))
endif
for [j, s] in map(range(0, l), '[v:val, 0]') + types
if i + 1 == j || t || s && i != l
let q = s ? (has_key(get(c, d, []), j) ? c[d][j][0] : has_key(get(c, 'tabline', {}), j) ? c.tabline[j][0] : get(c.normal, j, zs)[0]) : (j != l ? get(zs, j, ms) :ms)
exec printf('hi LightLine%s_%s_%s_%s guifg=%s guibg=%s ctermfg=%s ctermbg=%s', p, mode, i, j, r[1], q[1], r[3], q[3])
endif
endfor
endfor
endfor
exec printf('hi LightLineMiddle_%s guifg=%s guibg=%s ctermfg=%s ctermbg=%s %s', mode, ms[0], ms[1], ms[2], ms[3], s:term(ms))
endfor
endfunction
function! s:subseparator(components, subseparator, expanded) abort
let [a, c, f, v] = [ a:components, s:lightline.component, s:lightline.component_function, s:lightline.component_visible_condition ]
let xs = map(range(len(a:components)), 'a:expanded[v:val] ? "1" :
\ has_key(f, a[v:val]) ? (exists("*".f[a[v:val]]) ? "" : "exists(\"*".f[a[v:val]]."\")&&").f[a[v:val]]."()!=#\"\"" :
\ has_key(v, a[v:val]) ? "(" . v[a[v:val]] . ")" : has_key(c, a[v:val]) ? "1" : "0"')
return '%{' . (xs[0] ==# '1' ? '' : xs[0] . '&&(') . join(xs[1:], '||') . (xs[0] ==# '1' ? '' : ')') . '?"' . a:subseparator . '":""}'
endfunction
function! lightline#concatenate(xs, right) abort
let separator = a:right ? s:lightline.subseparator.right : s:lightline.subseparator.left
return join(filter(copy(a:xs), 'v:val !=# ""'), ' ' . separator . ' ')
endfunction
function! lightline#statusline(inactive) abort
if a:inactive && !has_key(s:highlight, 'inactive')
call lightline#highlight('inactive')
endif
return s:line(0, a:inactive)
endfunction
function! s:normalize(result) abort
if type(a:result) == 3
return map(a:result, 'type(v:val) == 1 ? v:val : string(v:val)')
elseif type(a:result) == 1
return [a:result]
else
return [string(a:result)]
endif
endfunction
function! s:evaluate_expand(component) abort
try
let result = call(a:component, [])
if type(result) == 1 && result ==# ''
return []
endif
catch
return []
endtry
return map(type(result) == 3 ? (result + [[], [], []])[:2] : [[], [result], []], 'filter(s:normalize(v:val), "v:val !=# ''''")')
endfunction
function! s:convert(name, index) abort
if has_key(s:lightline.component_expand, a:name)
let type = get(s:lightline.component_type, a:name, a:index)
return filter(s:map(s:evaluate_expand(s:lightline.component_expand[a:name]), '[v:val, 1, v:key == 1 ? "' . type . '" : "' . a:index . '"]'), 'v:val[0] != []')
else
return [[[a:name], 0, a:index]]
endif
endfunction
function! s:flatten_twice(xss) abort
let ys = []
for xs in a:xss
for x in xs
let ys += x
endfor
endfor
return ys
endfunction
if v:version > 702 || v:version == 702 && has('patch295')
let s:map = function('map')
else
function! s:map(xs, f) abort
let ys = []
for i in range(len(a:xs))
call extend(ys, map(a:xs[(i):(i)], substitute(a:f, 'v:key', i, 'g')))
endfor
return ys
endfunction
endif
function! s:expand(components) abort
let components = []
let expanded = []
let indices = []
let previndex = -1
let xs = s:flatten_twice(s:map(deepcopy(a:components), 'map(v:val, "s:convert(v:val, ''" . v:key . "'')")'))
for [component, expand, index] in xs
if previndex != index
call add(indices, index)
call add(components, [])
call add(expanded, [])
endif
call extend(components[-1], component)
call extend(expanded[-1], repeat([expand], len(component)))
let previndex = index
endfor
call add(indices, string(len(a:components)))
return [components, expanded, indices]
endfunction
function! s:line(tabline, inactive) abort
let _ = a:tabline ? '' : '%{lightline#link()}'
if s:lightline.palette == {}
call lightline#colorscheme()
endif
let [l, r] = a:tabline ? [s:lightline.tab_llen, s:lightline.tab_rlen] : [s:lightline.llen, s:lightline.rlen]
let [p, s] = a:tabline ? [s:lightline.tabline_separator, s:lightline.tabline_subseparator] : [s:lightline.separator, s:lightline.subseparator]
let [c, f, t] = [s:lightline.component, s:lightline.component_function, s:lightline.component_type]
let mode = a:tabline ? 'tabline' : a:inactive ? 'inactive' : 'active'
let l_ = has_key(s:lightline, mode) ? s:lightline[mode].left : s:lightline.active.left
let [lt, lc, ll] = s:expand(copy(l_))
let r_ = has_key(s:lightline, mode) ? s:lightline[mode].right : s:lightline.active.right
let [rt, rc, rl] = s:expand(copy(r_))
for i in range(len(lt))
let _ .= '%#LightLineLeft_' . mode . '_' . ll[i] . '#'
for j in range(len(lt[i]))
let x = lc[i][j] ? lt[i][j] : has_key(f, lt[i][j]) ? (exists('*' . f[lt[i][j]]) ? '%{' . f[lt[i][j]] . '()}' : '%{exists("*' . f[lt[i][j]] . '")?' . f[lt[i][j]] . '():""}') : get(c, lt[i][j], '')
let _ .= has_key(t, lt[i][j]) && t[lt[i][j]] ==# 'raw' || x ==# '' ? x : '%( ' . x . ' %)'
if j < len(lt[i]) - 1 && s.left !=# ''
let _ .= s:subseparator(lt[i][(j):], s.left, lc[i][(j):])
endif
endfor
let _ .= '%#LightLineLeft_' . mode . '_' . ll[i] . '_' . ll[i + 1] . '#'
let _ .= i < l + len(lt) - len(l_) && ll[i] < l || ll[i] != ll[i + 1] ? p.left : len(lt[i]) ? s.left : ''
endfor
let _ .= '%#LightLineMiddle_' . mode . '#%='
for i in reverse(range(len(rt)))
let _ .= '%#LightLineRight_' . mode . '_' . rl[i] . '_' . rl[i + 1] . '#'
let _ .= i < r + len(rt) - len(r_) && rl[i] < r || rl[i] != rl[i + 1] ? p.right : len(rt[i]) ? s.right : ''
let _ .= '%#LightLineRight_' . mode . '_' . rl[i] . '#'
for j in range(len(rt[i]))
let x = rc[i][j] ? rt[i][j] : has_key(f, rt[i][j]) ? (exists('*' . f[rt[i][j]]) ? '%{' . f[rt[i][j]] . '()}' : '%{exists("*' . f[rt[i][j]] . '")?' . f[rt[i][j]] . '():""}') : get(c, rt[i][j], '')
let _ .= has_key(t, rt[i][j]) && t[rt[i][j]] ==# 'raw' || x ==# '' ? x : '%( ' . x . ' %)'
if j < len(rt[i]) - 1 && s.right !=# ''
let _ .= s:subseparator(rt[i][(j):], s.right, rc[i][(j):])
endif
endfor
endfor
return _
endfunction
let s:tabnr = -1
let s:tabcnt = -1
let s:tabline = ''
function! lightline#tabline() abort
if !has_key(s:highlight, 'tabline')
call lightline#highlight('tabline')
endif
if s:lightline.tabline_configured || s:tabnr != tabpagenr() || s:tabcnt != tabpagenr('$')
let s:tabnr = tabpagenr()
let s:tabcnt = tabpagenr('$')
let s:tabline = s:line(1, 0)
endif
return s:tabline
endfunction
function! lightline#tabs() abort
let [x, y, z] = [[], [], []]
let nr = tabpagenr()
let cnt = tabpagenr('$')
for i in range(1, cnt)
call add(i < nr ? x : i == nr ? y : z, '%'. i . 'T%{lightline#onetab(' . i . ',' . (i == nr) . ')}' . (i == cnt ? '%T' : ''))
endfor
let abbr = '...'
let n = min([max([s:lightline.winwidth / 40, 2]), 8])
if len(x) > n && len(z) > n
let x = extend(add(x[:n/2-1], abbr), x[-(n+1)/2:])
let z = extend(add(z[:(n+1)/2-1], abbr), z[-n/2:])
elseif len(x) + len(z) > 2 * n
if len(x) > n
let x = extend(add(x[:(2*n-len(z))/2-1], abbr), x[-(2*n-len(z)+1)/2:])
elseif len(z) > n
let z = extend(add(z[:(2*n-len(x)+1)/2-1], abbr), z[-(2*n-len(x))/2:])
endif
endif
return [x, y, z]
endfunction
function! lightline#onetab(n, active) abort
let _ = []
for name in a:active ? s:lightline.tab.active : s:lightline.tab.inactive
if has_key(s:lightline.tab_component_function, name)
call add(_, call(s:lightline.tab_component_function[name], [a:n]))
else
call add(_, get(s:lightline.tab_component, name, ''))
endif
endfor
return join(filter(_, 'v:val !=# ""'), ' ')
endfunction
function! lightline#error(msg) abort
echohl ErrorMsg
echomsg 'lightline.vim: '.a:msg
echohl None
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -0,0 +1,228 @@
" =============================================================================
" Filename: autoload/lightline/colorscheme.vim
" Author: itchyny
" License: MIT License
" Last Change: 2015/03/18 08:37:17.
" =============================================================================
let s:save_cpo = &cpo
set cpo&vim
let s:cuicolor = {
\ 'black' : 16,
\ 'white' : 231,
\
\ 'darkestgreen' : 22,
\ 'darkgreen' : 28,
\ 'mediumgreen' : 70,
\ 'brightgreen' : 148,
\
\ 'darkestcyan' : 23,
\ 'mediumcyan' : 117,
\
\ 'darkestblue' : 24,
\ 'darkblue' : 31,
\
\ 'darkestred' : 52,
\ 'darkred' : 88,
\ 'mediumred' : 124,
\ 'brightred' : 160,
\ 'brightestred' : 196,
\
\ 'darkestpurple' : 55,
\ 'mediumpurple' : 98,
\ 'brightpurple' : 189,
\
\ 'brightorange' : 208,
\ 'brightestorange': 214,
\
\ 'gray0' : 233,
\ 'gray1' : 235,
\ 'gray2' : 236,
\ 'gray3' : 239,
\ 'gray4' : 240,
\ 'gray5' : 241,
\ 'gray6' : 244,
\ 'gray7' : 245,
\ 'gray8' : 247,
\ 'gray9' : 250,
\ 'gray10' : 252,
\
\ 'yellow' : 136,
\ 'orange' : 166,
\ 'red' : 160,
\ 'magenta' : 125,
\ 'violet' : 61,
\ 'blue' : 33,
\ 'cyan' : 37,
\ 'green' : 64,
\ }
let s:guicolor = {
\ 'black' : '#000000',
\ 'white' : '#ffffff',
\
\ 'darkestgreen' : '#005f00',
\ 'darkgreen' : '#008700',
\ 'mediumgreen' : '#5faf00',
\ 'brightgreen' : '#afdf00',
\
\ 'darkestcyan' : '#005f5f',
\ 'mediumcyan' : '#87dfff',
\
\ 'darkestblue' : '#005f87',
\ 'darkblue' : '#0087af',
\
\ 'darkestred' : '#5f0000',
\ 'darkred' : '#870000',
\ 'mediumred' : '#af0000',
\ 'brightred' : '#df0000',
\ 'brightestred' : '#ff0000',
\
\ 'darkestpurple' : '#5f00af',
\ 'mediumpurple' : '#875fdf',
\ 'brightpurple' : '#dfdfff',
\
\ 'brightorange' : '#ff8700',
\ 'brightestorange': '#ffaf00',
\
\ 'gray0' : '#121212',
\ 'gray1' : '#262626',
\ 'gray2' : '#303030',
\ 'gray3' : '#4e4e4e',
\ 'gray4' : '#585858',
\ 'gray5' : '#606060',
\ 'gray6' : '#808080',
\ 'gray7' : '#8a8a8a',
\ 'gray8' : '#9e9e9e',
\ 'gray9' : '#bcbcbc',
\ 'gray10' : '#d0d0d0',
\
\ 'yellow' : '#b58900',
\ 'orange' : '#cb4b16',
\ 'red' : '#dc322f',
\ 'magenta' : '#d33682',
\ 'violet' : '#6c71c4',
\ 'blue' : '#268bd2',
\ 'cyan' : '#2aa198',
\ 'green' : '#859900',
\ }
function! s:convert(rgb) abort
let rgb = map(matchlist(a:rgb, '#\(..\)\(..\)\(..\)')[1:3], '0 + ("0x".v:val)')
if len(rgb) == 0
return 0
endif
if rgb[0] == 0xc0 && rgb[1] == 0xc0 && rgb[2] == 0xc0
return 7
elseif rgb[0] == 0x80 && rgb[1] == 0x80 && rgb[2] == 0x80
return 8
elseif (rgb[0] == 0x80 || rgb[0] == 0x00) && (rgb[1] == 0x80 || rgb[1] == 0x00) && (rgb[2] == 0x80 || rgb[2] == 0x00)
return (rgb[0] / 0x80) + (rgb[1] / 0x80) * 2 + (rgb[1] / 0x80) * 4
elseif abs(rgb[0]-rgb[1]) < 3 && abs(rgb[1]-rgb[2]) < 3 && abs(rgb[2]-rgb[0]) < 3
return s:black((rgb[0] + rgb[1] + rgb[2]) / 3)
else
return 16 + ((s:nr(rgb[0]) * 6) + s:nr(rgb[1])) * 6 + s:nr(rgb[2])
endif
endfunction
function! s:black(x) abort
if a:x < 0x04
return 16
elseif a:x > 0xf4
return 231
elseif index([0x00, 0x5f, 0x87, 0xaf, 0xdf, 0xff], a:x) >= 0
let l = a:x / 0x30
return ((l * 6) + l) * 6 + l + 16
else
return 232 + (a:x < 8 ? 0 : a:x < 0x60 ? (a:x-8)/10 : a:x < 0x76 ? (a:x-0x60)/6+9 : (a:x-8)/10)
endif
endfunction
function! s:nr(x) abort
return a:x < 0x2f ? 0 : a:x < 0x73 ? 1 : a:x < 0x9b ? 2 : a:x < 0xc7 ? 3 : a:x < 0xef ? 4 : 5
endfunction
function! s:rgb(r, g, b) abort
return printf('#%02x%02x%02x', a:r, a:g, a:b)
endfunction
function! s:upconvert(nr) abort
let x = a:nr * 1
if x < 7
let [b, rg] = [x / 4, x % 4]
let [g, r] = [rg / 2, rg % 2]
return s:rgb(r * 0x80, g * 0x80, b * 0x80)
elseif x == 7
return s:rgb(0xc0, 0xc0, 0xc0)
elseif x == 8
return s:rgb(0x80, 0x80, 0x80)
elseif x < 16
let y = x - 8
let [b, rg] = [y / 4, y % 4]
let [g, r] = [rg / 2, rg % 2]
return s:rgb(r * 0xff, g * 0xff, b * 0xff)
elseif x < 232
let y = x - 16
let [rg, b] = [y / 6, y % 6]
let [r, g] = [rg / 6, rg % 6]
let l = [0x00, 0x5f, 0x87, 0xaf, 0xdf, 0xff]
return s:rgb(l[r], l[g], l[b])
elseif x < 241
let k = (x - 232) * 10 + 8
return s:rgb(k, k, k)
elseif x < 243
let k = (x - 241) * 6 + 0x60
return s:rgb(k, k, k)
else
let k = (x - 232) * 10 + 8
return s:rgb(k, k, k)
endif
endfunction
function! lightline#colorscheme#fill(p) abort
for k in values(a:p)
for l in values(k)
for m in l
if len(m) < 4
if type(m[0]) == 1 && type(m[1]) == 1
if m[0] =~# '^\d\+$' && m[1] =~# '^\d\+$'
call insert(m, s:upconvert(m[1]), 0)
call insert(m, s:upconvert(m[1]), 0)
else
call insert(m, get(s:cuicolor, m[0], s:convert(m[0])), 2)
call insert(m, get(s:cuicolor, m[1], s:convert(m[1])), 3)
let m[0] = get(s:guicolor, m[0], m[0])
let m[1] = get(s:guicolor, m[1], m[1])
endif
elseif type(m[0]) == 0 && type(m[1]) == 0
call insert(m, s:upconvert(m[1]), 0)
call insert(m, s:upconvert(m[1]), 0)
endif
endif
endfor
endfor
endfor
return a:p
endfunction
function! lightline#colorscheme#flatten(p) abort
for k in values(a:p)
for l in values(k)
for m in range(len(l))
let attr =