mirror of
https://github.com/itchyny/lightline.vim.git
synced 2025-11-12 21:43:50 -05:00
add tutorial section to README.md
This commit is contained in:
207
README.md
207
README.md
@@ -66,3 +66,210 @@ MIT License
|
|||||||
|
|
||||||
2. Install with `:NeoBundleInstall`.
|
2. Install with `:NeoBundleInstall`.
|
||||||
|
|
||||||
|
## Configuration tutorial
|
||||||
|
In default, the statusline looks like:
|
||||||
|

|
||||||
|
If you want a wombat colorscheme, add the folowing settin to your .vimrc:
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ }
|
||||||
|
```
|
||||||
|
to get:
|
||||||
|

|
||||||
|
|
||||||
|
If you have installed vim-fugitive, the branch status is automatically available:
|
||||||
|

|
||||||
|
but you find it annoying! So you add to your .vimrc:
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'readonly', 'filename', 'modified' ] ] }
|
||||||
|
\ }
|
||||||
|
```
|
||||||
|

|
||||||
|
OK. The branch section is removed.
|
||||||
|
|
||||||
|
However, you find the readonly mark is not cool:
|
||||||
|

|
||||||
|
So you add the component setting (the following setting is effective with the integrated font for vim-powerline):
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'readonly', 'filename', 'modified' ] ] },
|
||||||
|
\ 'component': {
|
||||||
|
\ 'readonly': '%{&readonly?"⭤":""}'
|
||||||
|
\ }
|
||||||
|
\ }
|
||||||
|
```
|
||||||
|

|
||||||
|
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',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'readonly', 'filename', 'modified' ] ] },
|
||||||
|
\ 'component': {
|
||||||
|
\ 'readonly': '%{&readonly?"⭤":""}'
|
||||||
|
\ },
|
||||||
|
\ 'separator': { 'left': '⮀', 'right': '⮂' },
|
||||||
|
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
|
||||||
|
\ }
|
||||||
|
```
|
||||||
|

|
||||||
|
Hurrah! Cool!
|
||||||
|
|
||||||
|
|
||||||
|
Now, you look into a help file to find the marks annoying.
|
||||||
|
Help files are readonly and no-modifiable? We know, of cource!
|
||||||
|

|
||||||
|
OK, so you again edit your .vimrc.
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'readonly', 'filename', 'modified' ] ] },
|
||||||
|
\ 'component': {
|
||||||
|
\ 'readonly': '%{&filetype!="help"&& &readonly?"⭤":""}',
|
||||||
|
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
|
||||||
|
\ },
|
||||||
|
\ 'separator': { 'left': '⮀', 'right': '⮂' },
|
||||||
|
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
|
||||||
|
\ }
|
||||||
|
```
|
||||||
|

|
||||||
|
Huh? Weird!
|
||||||
|
The component does not collapse even if it has no information!
|
||||||
|
In order to avoid this, you set expressions to component\_flag, which becomes 1 only when the corresponding components have information.
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'readonly', 'filename', 'modified' ] ] },
|
||||||
|
\ 'component': {
|
||||||
|
\ 'readonly': '%{&filetype!="help"&& &readonly?"⭤":""}',
|
||||||
|
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
|
||||||
|
\ },
|
||||||
|
\ 'component_flag': {
|
||||||
|
\ 'readonly': '(&filetype!="help"&& &readonly)',
|
||||||
|
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))'
|
||||||
|
\ },
|
||||||
|
\ 'separator': { 'left': '⮀', 'right': '⮂' },
|
||||||
|
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
|
||||||
|
\ }
|
||||||
|
```
|
||||||
|

|
||||||
|
Okey. Works nice.
|
||||||
|
|
||||||
|
|
||||||
|
However, you may wonder we cannot gather these settings?
|
||||||
|
Or, if you want to do something more complicated?
|
||||||
|
|
||||||
|
|
||||||
|
In fact, the components can be created using functions.
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'readonly', 'filename', 'modified' ] ] },
|
||||||
|
\ 'component_func': {
|
||||||
|
\ 'readonly': 'MyReadonly',
|
||||||
|
\ 'modified': 'MyModified'
|
||||||
|
\ },
|
||||||
|
\ 'separator': { 'left': '⮀', 'right': '⮂' },
|
||||||
|
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
|
||||||
|
\ }
|
||||||
|
function! MyModified()
|
||||||
|
if &filetype == "help"
|
||||||
|
return ""
|
||||||
|
elseif &modified
|
||||||
|
return "+"
|
||||||
|
elseif &modifiable
|
||||||
|
return ""
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
function! MyReadonly()
|
||||||
|
if &filetype == "help"
|
||||||
|
return ""
|
||||||
|
elseif &readonly
|
||||||
|
return "⭤"
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
```
|
||||||
|

|
||||||
|
Fine and readable!
|
||||||
|
|
||||||
|
|
||||||
|
Finally, you come up with concatenating the three components:
|
||||||
|

|
||||||
|
Now you may now what to do.
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'colorscheme': 'wombat',
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'filename' ] ] },
|
||||||
|
\ 'component_func': {
|
||||||
|
\ 'filename': 'MyFilename',
|
||||||
|
\ 'readonly': 'MyReadonly',
|
||||||
|
\ 'modified': 'MyModified'
|
||||||
|
\ },
|
||||||
|
\ 'separator': { 'left': '⮀', 'right': '⮂' },
|
||||||
|
\ 'subseparator': { 'left': '⮁', 'right': '⮃' }
|
||||||
|
\ }
|
||||||
|
function! MyModified()
|
||||||
|
if &filetype == "help"
|
||||||
|
return ""
|
||||||
|
elseif &modified
|
||||||
|
return "+"
|
||||||
|
elseif &modifiable
|
||||||
|
return ""
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
function! MyReadonly()
|
||||||
|
if &filetype == "help"
|
||||||
|
return ""
|
||||||
|
elseif &readonly
|
||||||
|
return "⭤"
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
function! MyFilename()
|
||||||
|
return ('' != MyReadonly() ? MyReadonly() . ' ' : '') .
|
||||||
|
\ ('' != expand('%t') ? expand('%t') : '[No Name]') .
|
||||||
|
\ ('' != MyModified() ? ' ' . MyModified() : '')
|
||||||
|
endfunction
|
||||||
|
```
|
||||||
|
Define your own filename component. It has priority over the component lightline has.
|
||||||
|

|
||||||
|
Looks nice.
|
||||||
|
|
||||||
|
Of cource, you can name your component as you wish.
|
||||||
|
```vim
|
||||||
|
let g:lightline = {
|
||||||
|
\ 'active': {
|
||||||
|
\ 'left': [ [ 'mode', 'paste' ],
|
||||||
|
\ [ 'my_filename' ] ] },
|
||||||
|
\ 'component_func': {
|
||||||
|
\ 'my_filename': 'MyFilename', ...
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the end of the tutorial. Good luck with your nice statusline.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
" Version: 0.0
|
" Version: 0.0
|
||||||
" Author: itchyny
|
" Author: itchyny
|
||||||
" License: MIT License
|
" License: MIT License
|
||||||
" Last Change: 2013/08/22 14:21:34.
|
" Last Change: 2013/08/22 15:32:52.
|
||||||
" =============================================================================
|
" =============================================================================
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
@@ -163,9 +163,12 @@ function! lightline#highlight(mode)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! lightline#subseparator(x, y, s)
|
function! lightline#subseparator(x, y, s)
|
||||||
return '%{('.get(g:lightline.component_flag,a:x,has_key(g:lightline.component_func,a:x)?'!!strlen('.g:lightline.component_func[a:x].'())':"1").')*('.
|
return '%{('.(has_key(g:lightline.component_func,a:x)?'!!strlen('.(g:lightline.component_func[a:x]).'())':get(g:lightline.component_flag,a:x,"1")).')*('.
|
||||||
\join(map(copy(a:y),'get(g:lightline.component_flag,v:val,has_key(g:lightline.component_func,v:val)?'.
|
\join(map(copy(a:y),'(has_key(g:lightline.component_func,v:val)?"!!strlen(".g:lightline.component_func[v:val]."())":'.
|
||||||
\'"!!strlen(".g:lightline.component_func[v:val]."())":has_key(g:lightline.component,v:val)?"1":"0")'),'+').")?('".a:s."'):''}"
|
\'get(g:lightline.component_flag,v:val,has_key(g:lightline.component,v:val)?"1":"0"))'),'+').")?('".a:s."'):''}"
|
||||||
|
" return '%{('.get(g:lightline.component_flag,a:x,has_key(g:lightline.component_func,a:x)?'!!strlen('.g:lightline.component_func[a:x].'())':"1").')*('.
|
||||||
|
" \join(map(copy(a:y),'get(g:lightline.component_flag,v:val,has_key(g:lightline.component_func,v:val)?'.
|
||||||
|
" \'"!!strlen(".g:lightline.component_func[v:val]."())":has_key(g:lightline.component,v:val)?"1":"0")'),'+').")?('".a:s."'):''}"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! lightline#statusline(inactive)
|
function! lightline#statusline(inactive)
|
||||||
@@ -176,7 +179,8 @@ function! lightline#statusline(inactive)
|
|||||||
for i in range(len(left))
|
for i in range(len(left))
|
||||||
let _ .= printf('%%#LightLineLeft_%s_%d#', mode, i)
|
let _ .= printf('%%#LightLineLeft_%s_%d#', mode, i)
|
||||||
for j in range(len(left[i]))
|
for j in range(len(left[i]))
|
||||||
let _ .= '%( '.get(g:lightline.component,left[i][j],has_key(g:lightline.component_func,left[i][j])?'%{'.g:lightline.component_func[left[i][j]].'()}':'').' %)'
|
" let _ .= '%( '.get(g:lightline.component,left[i][j],has_key(g:lightline.component_func,left[i][j])?'%{'.g:lightline.component_func[left[i][j]].'()}':'').' %)'
|
||||||
|
let _ .= '%( '.(has_key(g:lightline.component_func,left[i][j])?'%{'.g:lightline.component_func[left[i][j]].'()}':get(g:lightline.component,left[i][j],'')).' %)'
|
||||||
if j < len(left[i]) - 1
|
if j < len(left[i]) - 1
|
||||||
let _ .= lightline#subseparator(left[i][j], left[i][j+1:], g:lightline.subseparator.left)
|
let _ .= lightline#subseparator(left[i][j], left[i][j+1:], g:lightline.subseparator.left)
|
||||||
endif
|
endif
|
||||||
@@ -191,7 +195,8 @@ function! lightline#statusline(inactive)
|
|||||||
if j
|
if j
|
||||||
let _ .= lightline#subseparator(right[i][j], right[i][:j-1], g:lightline.subseparator.right)
|
let _ .= lightline#subseparator(right[i][j], right[i][:j-1], g:lightline.subseparator.right)
|
||||||
endif
|
endif
|
||||||
let _ .= '%( '.get(g:lightline.component,right[i][j],has_key(g:lightline.component_func,right[i][j])?'%{'.g:lightline.component_func[right[i][j]].'()}':'').' %)'
|
" let _ .= '%( '.get(g:lightline.component,right[i][j],has_key(g:lightline.component_func,right[i][j])?'%{'.g:lightline.component_func[right[i][j]].'()}':'').' %)'
|
||||||
|
let _ .= '%( '.(has_key(g:lightline.component_func,right[i][j])?'%{'.g:lightline.component_func[right[i][j]].'()}':get(g:lightline.component,right[i][j],'')).' %)'
|
||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
return _
|
return _
|
||||||
|
|||||||
Reference in New Issue
Block a user