remove fugitive component

This commit is contained in:
itchyny
2013-08-23 20:49:55 +09:00
parent 5555c5362f
commit 1a2799defc
3 changed files with 237 additions and 161 deletions

217
README.md
View File

@@ -86,96 +86,71 @@ MIT License
## Configuration tutorial ## Configuration tutorial
In default, the statusline looks like: In default, the statusline looks like:
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/1.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/1.png)
If you want a wombat colorscheme, add the following setting to your .vimrc (or \_vimrc on Windows): If you want a colorscheme which looks well with the wombat colorscheme, add the following setting to your .vimrc (or \_vimrc on Windows):
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ } \ }
``` ```
to get: to get:
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/2.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/2.png)
If you have installed [vim-fugitive](https://github.com/tpope/vim-fugitive), the branch status is automatically available: You may think that the default read-only mark is not so cool:
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/3.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/3.png)
but you find it annoying! Then you add to your .vimrc: Then edit the readonly component.
The lightline components are stored in `g:lightline.component`.
So you add the setting of `g:lightline.component.readonly` in your .vimrc. (the following setting is effective with the patched font for vim-powerline):
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ 'active': { \ 'component': {
\ 'left': [ [ 'mode', 'paste' ], \ 'readonly': '%{&readonly?"⭤":""}',
\ [ 'readonly', 'filename', 'modified' ] ] } \ }
\ } \ }
``` ```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/4.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/4.png)
OK. The branch section has been removed.
The `g:lightline.active.left` stands for the components which appear on the left hand side, for the active window.
You think that the read-only mark is not so cool:
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/5.png)
So you add the component setting (the following setting is effective with the patched font for vim-powerline):
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] },
\ 'component': {
\ 'readonly': '%{&readonly?"⭤":""}'
\ }
\ }
```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/6.png)
How nice! How nice!
But the boundaries are quadrilateral. You may miss the powerline. But the boundaries are quadrilateral. You may miss the powerline.
You have installed a cool font for powerlines, so you can use it. You have installed a cool font for powerlines, so you can use it.
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] },
\ 'component': { \ 'component': {
\ 'readonly': '%{&readonly?"⭤":""}' \ 'readonly': '%{&readonly?"⭤":""}',
\ }, \ },
\ 'separator': { 'left': '⮀', 'right': '⮂' }, \ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' } \ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ } \ }
``` ```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/7.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/5.png)
Hurrah! Cool! Hurrah! Cool!
Now, you look into a help file to find the marks annoying. Now, you look into a help file to find the marks annoying.
Help files are read-only and no-modifiable? We know, of course! Help files are read-only and no-modifiable? We know that!
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/8.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/6.png)
OK, so you again edit your .vimrc. OK, so you again edit your .vimrc.
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] },
\ 'component': { \ 'component': {
\ 'readonly': '%{&filetype!="help"&& &readonly?"⭤":""}', \ 'readonly': '%{&filetype=="help"?"":&readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}' \ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ }, \ },
\ 'separator': { 'left': '⮀', 'right': '⮂' }, \ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' } \ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ } \ }
``` ```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/9.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/7.png)
Huh? Weird! Huh? Weird!
The component does not collapse even if it has no information! The component does not collapse even if it has no information!
In order to avoid this, you set expressions to component\_visible\_condition, which should become 1 only when the corresponding components have information. In order to avoid this situation, you set expressions to component\_visible\_condition, which should become 1 only when the corresponding components have information.
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] },
\ 'component': { \ 'component': {
\ 'readonly': '%{&filetype!="help"&& &readonly?"⭤":""}', \ 'readonly': '%{&filetype=="help"?"":&readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}' \ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ }, \ },
\ 'component_visible_condition': { \ 'component_visible_condition': {
@@ -186,29 +161,113 @@ In order to avoid this, you set expressions to component\_visible\_condition, wh
\ 'subseparator': { 'left': '⮁', 'right': '⮃' } \ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ } \ }
``` ```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/8.png)
Okay. It works nice.
How does lightline desides the components to show in the statusline?
It's very simple.
The variable to control the components is `g:lightline.active.left` and `g:lightline.active.left`.
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': '⮃' }
\ }
```
The plugin arranges all the component:
![lightline.vim - tutorial](https://raw.github.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.github.com/wiki/itchyny/lightline.vim/image/tutorial/10.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/10.png)
Okay. Works nice. If the file is not read-only (more common case), the read-only component does not show up.
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/11.png)
However, you may wonder we cannot gather these settings. Again look into `g:lightline.active.left`.
Or, if you want to do something more complicated? ```vim
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] ...
```
And the screen shot.
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/9.png)
The mode and paste component are displayed in the same group.
And The read-only, filename and modified component are in the second group.
It corresponds to the structure of `g:lightline.active.left`.
GitHub branch is important for us.
And is a default component in powerline.
However, lightline does not provide the branch feature in default.
In order to show the branch in statusline, firstly you install the [vim-fugitive](https://github.com/tpope/vim-fugitive) plugin.
Then edit the g:lightline in your .vimrc.
+ Add 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.github.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. In fact, the components can be created using functions.
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ 'active': { \ 'active': {
\ 'left': [ [ 'mode', 'paste' ], \ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] }, \ [ 'fugitive', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': { \ 'component_function': {
\ 'fugitive': 'MyFugitive',
\ 'readonly': 'MyReadonly', \ 'readonly': 'MyReadonly',
\ 'modified': 'MyModified' \ 'modified': 'MyModified'
\ }, \ },
\ 'separator': { 'left': '⮀', 'right': '⮂' }, \ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' } \ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ } \ }
function! MyModified()
function! MyModified()
if &filetype == "help" if &filetype == "help"
return "" return ""
elseif &modified elseif &modified
@@ -218,8 +277,9 @@ In fact, the components can be created using functions.
else else
return "" return ""
endif endif
endfunction endfunction
function! MyReadonly()
function! MyReadonly()
if &filetype == "help" if &filetype == "help"
return "" return ""
elseif &readonly elseif &readonly
@@ -227,30 +287,36 @@ In fact, the components can be created using functions.
else else
return "" return ""
endif endif
endfunction endfunction
function! MyFugitive()
return exists('*fugitive#head') ? fugitive#head()
endfunction
``` ```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/11.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/13.png)
Fine and readable! Fine and readable!
Finally, you come up with concatenating the three components: the read-only mark, the filename and the modified mark. Finally, you come up with concatenating the three components: the read-only mark, the filename and the modified mark.
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/12.png)
Now you may know what to do. Now you may know what to do.
```vim ```vim
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'wombat', \ 'colorscheme': 'wombat',
\ 'active': { \ 'active': {
\ 'left': [ [ 'mode', 'paste' ], \ 'left': [ [ 'mode', 'paste' ],
\ [ 'filename' ] ] }, \ [ 'fugitive', 'filename' ] ]
\ },
\ 'component_function': { \ 'component_function': {
\ 'filename': 'MyFilename', \ 'fugitive': 'MyFugitive',
\ 'readonly': 'MyReadonly', \ 'readonly': 'MyReadonly',
\ 'modified': 'MyModified' \ 'modified': 'MyModified',
\ 'filename': 'MyFilename'
\ }, \ },
\ 'separator': { 'left': '⮀', 'right': '⮂' }, \ 'separator': { 'left': '⮀', 'right': '⮂' },
\ 'subseparator': { 'left': '⮁', 'right': '⮃' } \ 'subseparator': { 'left': '⮁', 'right': '⮃' }
\ } \ }
function! MyModified()
function! MyModified()
if &filetype == "help" if &filetype == "help"
return "" return ""
elseif &modified elseif &modified
@@ -260,8 +326,9 @@ Now you may know what to do.
else else
return "" return ""
endif endif
endfunction endfunction
function! MyReadonly()
function! MyReadonly()
if &filetype == "help" if &filetype == "help"
return "" return ""
elseif &readonly elseif &readonly
@@ -269,16 +336,28 @@ Now you may know what to do.
else else
return "" return ""
endif endif
endfunction endfunction
function! MyFilename()
function! MyFugitive()
return exists('*fugitive#head') ? fugitive#head() : ''
endfunction
function! MyFilename()
return ('' != MyReadonly() ? MyReadonly() . ' ' : '') . return ('' != MyReadonly() ? MyReadonly() . ' ' : '') .
\ ('' != expand('%t') ? expand('%t') : '[No Name]') . \ ('' != expand('%t') ? expand('%t') : '[No Name]') .
\ ('' != MyModified() ? ' ' . MyModified() : '') \ ('' != MyModified() ? ' ' . MyModified() : '')
endfunction endfunction
``` ```
Define your own filename component. Your component has priority over the default component. Define your own filename component. Your component has priority over the default component.
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/13.png) ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/14.png)
Looks nice. Oops! We forgot the cool mark for the branch component! (work with the patched font for vim-powerline)
```vim
function! MyFugitive()
return exists('*fugitive#head') && len(fugitive#head()) ? '⭠ '.fugitive#head() : ''
endfunction
```
![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/15.png)
How cool!!!
Of course, you can name your component as you wish. Of course, you can name your component as you wish.
```vim ```vim

View File

@@ -3,7 +3,7 @@
" Version: 0.0 " Version: 0.0
" Author: itchyny " Author: itchyny
" License: MIT License " License: MIT License
" Last Change: 2013/08/23 13:36:31. " Last Change: 2013/08/23 19:20:42.
" ============================================================================= " =============================================================================
let s:save_cpo = &cpo let s:save_cpo = &cpo
@@ -30,7 +30,7 @@ function! lightline#init()
let g:lightline = get(g:, 'lightline', {}) let g:lightline = get(g:, 'lightline', {})
let g:lightline.active = get(g:lightline, 'active', {}) let g:lightline.active = get(g:lightline, 'active', {})
call extend(g:lightline.active, { call extend(g:lightline.active, {
\ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'readonly', 'filename', 'modified' ] ], \ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'filename', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ], [ 'percent' ], [ 'fileformat', 'fileencoding', 'filetype' ] ] }, 'keep') \ 'right': [ [ 'lineinfo' ], [ 'percent' ], [ 'fileformat', 'fileencoding', 'filetype' ] ] }, 'keep')
let g:lightline.inactive = get(g:lightline, 'inactive', {}) let g:lightline.inactive = get(g:lightline, 'inactive', {})
call extend(g:lightline.inactive, { call extend(g:lightline.inactive, {
@@ -58,14 +58,12 @@ function! lightline#init()
\ 'fileformat': '%{&fileformat}', \ 'fileformat': '%{&fileformat}',
\ 'filetype': '%{strlen(&filetype)?&filetype:"no ft"}', \ 'filetype': '%{strlen(&filetype)?&filetype:"no ft"}',
\ 'percent': '%3p%%', \ 'percent': '%3p%%',
\ 'lineinfo': '%3l:%-2v', \ 'lineinfo': '%3l:%-2v' }, 'keep')
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}' }, 'keep')
let g:lightline.component_visible_condition = get(g:lightline, 'component_visible_condition', {}) let g:lightline.component_visible_condition = get(g:lightline, 'component_visible_condition', {})
call extend(g:lightline.component_visible_condition, { call extend(g:lightline.component_visible_condition, {
\ 'modified': '(&modified||!&modifiable)', \ 'modified': '(&modified||!&modifiable)',
\ 'readonly': '(&readonly)', \ 'readonly': '(&readonly)',
\ 'paste': '(&paste)', \ 'paste': '(&paste)' }, 'keep')
\ 'fugitive': '(exists("*fugitive#head")&&strlen(fugitive#head()))' }, 'keep')
let g:lightline.component_function = get(g:lightline, 'component_function', {}) let g:lightline.component_function = get(g:lightline, 'component_function', {})
let g:lightline.separator = get(g:lightline, 'separator', {}) let g:lightline.separator = get(g:lightline, 'separator', {})
call extend(g:lightline.separator, { 'left': '', 'right': '' }, 'keep') call extend(g:lightline.separator, { 'left': '', 'right': '' }, 'keep')

View File

@@ -4,7 +4,7 @@ Version: 0.0
Author: itchyny (https://github.com/itchyny) Author: itchyny (https://github.com/itchyny)
License: MIT License License: MIT License
Repository: https://github.com/itchyny/lightline.vim Repository: https://github.com/itchyny/lightline.vim
Last Change: 2013/08/23 07:11:18. Last Change: 2013/08/23 19:20:57.
CONTENTS *lightline-contents* CONTENTS *lightline-contents*
@@ -34,7 +34,7 @@ OPTIONS *lightline-options*
> >
let g:lightline.active = { let g:lightline.active = {
\ 'left': [ [ 'mode', 'paste' ], \ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'readonly', 'filename', 'modified' ] ], \ [ 'readonly', 'filename', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ], \ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ], \ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ] ] } \ [ 'fileformat', 'fileencoding', 'filetype' ] ] }
@@ -57,8 +57,7 @@ OPTIONS *lightline-options*
\ 'fileformat': '%{&fileformat}', \ 'fileformat': '%{&fileformat}',
\ 'filetype': '%{strlen(&filetype)?&filetype:"no ft"}', \ 'filetype': '%{strlen(&filetype)?&filetype:"no ft"}',
\ 'percent': '%3p%%', \ 'percent': '%3p%%',
\ 'lineinfo': '%3l:%-2v', \ 'lineinfo': '%3l:%-2v' }
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}' }
< <
g:lightline.component_visible_condition *g:lightline.component_visible_condition* g:lightline.component_visible_condition *g:lightline.component_visible_condition*
Dictionary of boolean expressions for the components. Dictionary of boolean expressions for the components.