No edit summary |
(Change to TipImported template + severe manual clean) |
||
Line 1: | Line 1: | ||
{{review}} |
{{review}} |
||
+ | {{TipImported |
||
− | {{Tip |
||
|id=885 |
|id=885 |
||
+ | |previous=884 |
||
− | |title=Switching between different statuslines |
||
+ | |next=886 |
||
− | |created=February 28, 2005 12:23 |
||
+ | |created=February 28, 2005 |
||
|complexity=intermediate |
|complexity=intermediate |
||
|author=Matous Jan Fialka |
|author=Matous Jan Fialka |
||
|version=6.0 |
|version=6.0 |
||
|rating=8/4 |
|rating=8/4 |
||
+ | }} |
||
− | |text= |
||
+ | With the following code in your vimrc, you can press F3 in normal mode to switch between several different status lines. |
||
− | The code between "---cut---" signs is a nice piece |
||
+ | <pre> |
||
− | of my ~/.vimrc which I really likes. It allows me to switch |
||
+ | "These three functions are just for example. |
||
+ | "It might be that these three functions are irrelevant |
||
+ | "in example statuslines, but they demonstrate that |
||
+ | "functions can be used in statusline too. |
||
+ | fu! Percent() |
||
+ | let byte = line2byte( line( "." ) ) + col( "." ) - 1 |
||
+ | let size = (line2byte( line( "$" ) + 1 ) - 1) |
||
+ | return (byte * 100) / size |
||
+ | endf |
||
+ | fu! FileEncoding() |
||
− | between several different statuslines by pressing F3 key (in |
||
+ | if &fileencoding == '' |
||
+ | return "is not set" |
||
+ | else |
||
+ | return &fenc |
||
+ | endif |
||
+ | endf |
||
+ | fu! GlobalEncoding() |
||
− | normal Vim mode). |
||
+ | if &fileencoding == '' |
||
+ | return "is not set" |
||
+ | else |
||
+ | return &enc |
||
+ | endif |
||
+ | endf |
||
+ | "And now the magical stuff! |
||
+ | "We define some statuslines at first. |
||
+ | let g:StatusLines{0}='[%1*%n%*]%= [%2*%03bD%* | %2*%5(0x%02BH%)%*] [%8oC=%1*%3{Percent()}%%%*] [%8c] : [%8l/%8L = %1*%3p%%%*]' |
||
+ | let g:StatusLines{1}='[%1*%n%*]%= [%1*GENC%* %10(%{GlobalEncoding()}%)] [%1*FENC%* %10(%{FileEncoding()}%)]' |
||
+ | let g:StatusLines{2}='[%1*%n%*]%= [%1*%F%*]' |
||
+ | let g:StatusLinesCurrent=-1 |
||
+ | "And we map switching on some unused key. |
||
+ | map <F3> :call ToggleStatusLine()<CR> |
||
+ | "Function that switch between several statuslines |
||
− | ---cut--- |
||
+ | fu! ToggleStatusLine() |
||
+ | let g:StatusLinesCurrent=g:StatusLinesCurrent+1 |
||
+ | if (!exists("g:StatusLines" . g:StatusLinesCurrent)) |
||
+ | let g:StatusLinesCurrent=0 |
||
+ | endif |
||
+ | let &statusline=g:StatusLines{g:StatusLinesCurrent} |
||
+ | endf |
||
+ | "We use the first one as default. |
||
− | "Theese three functions are just for example. |
||
+ | call ToggleStatusLine() |
||
+ | "Because I used some highlighting in the example statuslines |
||
− | "It might be that these three functions are irrelevant |
||
+ | "I put some highlighting definitions here too. |
||
+ | "The colours of statusline itself. |
||
+ | hi statusline term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=white |
||
+ | hi statuslinenc term=inverse,bold cterm=inverse,bold ctermfg=gray ctermbg=black |
||
+ | "Some other colours used in statuslines. |
||
− | "in example statuslines, but they demonstrate that |
||
+ | hi User1 term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=yellow |
||
+ | hi User2 term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=cyan |
||
+ | </pre> |
||
+ | This tip should be useful if you need more information than is able to be fit in a single statusline. |
||
− | "functions can be used in statusline too... |
||
+ | ==Comments== |
||
+ | If you don't like highlighting on the status line, here is a simpler version (it's just s/%[12]\?\*//g) |
||
+ | <pre> |
||
+ | let g:StatusLines{0}='[%n]%= [%03bD | %5(0x%02BH%)] [%8oC=%3{Percent()}%%] [%8c] : [%8l/%8L = %3p%%]' |
||
+ | let g:StatusLines{1}='[%n]%= [GENC %10(%{GlobalEncoding()}%)] [FENC %10(%{FileEncoding()}%)]' |
||
+ | let g:StatusLines{2}='[%n]%= [%F]' |
||
+ | </pre> |
||
− | fu! Percent() |
||
− | |||
− | let byte = line2byte( line( "." ) ) + col( "." ) - 1 |
||
− | |||
− | let size = (line2byte( line( "$" ) + 1 ) - 1) |
||
− | |||
− | return (byte * 100) / size |
||
− | |||
− | endf |
||
− | |||
− | |||
− | |||
− | fu! FileEncoding() |
||
− | |||
− | if &fileencoding == '' |
||
− | |||
− | return "is not set" |
||
− | |||
− | else |
||
− | |||
− | return &fenc |
||
− | |||
− | endif |
||
− | |||
− | endf |
||
− | |||
− | |||
− | |||
− | fu! GlobalEncoding() |
||
− | |||
− | if &fileencoding == '' |
||
− | |||
− | return "is not set" |
||
− | |||
− | else |
||
− | |||
− | return &enc |
||
− | |||
− | endif |
||
− | |||
− | endf |
||
− | |||
− | |||
− | |||
− | "And now the magical stuff! |
||
− | |||
− | "We define some statuslines at first... |
||
− | |||
− | |||
− | |||
− | let g:StatusLines{0}='[%1*%n%*]%= [%2*%03bD%* | %2*%5(0x%02BH%)%*] [%8oC=%1*%3{Percent()}%%%*] [%8c] : [%8l/%8L = %1*%3p%%%*]' |
||
− | |||
− | let g:StatusLines{1}='[%1*%n%*]%= [%1*GENC%* %10(%{GlobalEncoding()}%)] [%1*FENC%* %10(%{FileEncoding()}%)]' |
||
− | |||
− | let g:StatusLines{2}='[%1*%n%*]%= [%1*%F%*]' |
||
− | |||
− | let g:StatusLinesCurrent=-1 |
||
− | |||
− | |||
− | |||
− | "And we map switching on some unused key... |
||
− | |||
− | |||
− | |||
− | map <F3> :call ToggleStatusLine()<CR> |
||
− | |||
− | |||
− | |||
− | "Function that switch between several statuslines |
||
− | |||
− | "Made by M.W. from IRC#vim (many thanks for it)... |
||
− | |||
− | |||
− | |||
− | fu! ToggleStatusLine() |
||
− | |||
− | let g:StatusLinesCurrent=g:StatusLinesCurrent+1 |
||
− | |||
− | if (!exists("g:StatusLines" . g:StatusLinesCurrent)) |
||
− | |||
− | let g:StatusLinesCurrent=0 |
||
− | |||
− | endif |
||
− | |||
− | let &statusline=g:StatusLines{g:StatusLinesCurrent} |
||
− | |||
− | endf |
||
− | |||
− | |||
− | |||
− | "We use the first one as default... |
||
− | |||
− | |||
− | |||
− | call ToggleStatusLine() |
||
− | |||
− | |||
− | |||
− | "Because I used some highlighting in the example statuslines |
||
− | |||
− | "I put some highlighting definitions here too... |
||
− | |||
− | |||
− | |||
− | "The colours of statusline itself... |
||
− | |||
− | |||
− | |||
− | hi statusline term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=white |
||
− | |||
− | hi statuslinenc term=inverse,bold cterm=inverse,bold ctermfg=gray ctermbg=black |
||
− | |||
− | |||
− | |||
− | "Some other colours used in statuslines... |
||
− | |||
− | |||
− | |||
− | hi User1 term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=yellow |
||
− | |||
− | hi User2 term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=cyan |
||
− | |||
− | ---cut--- |
||
− | |||
− | |||
− | |||
− | I think that this tip should be very useful if you need |
||
− | |||
− | so much information that is unable to be fit in a single statusline... |
||
− | |||
− | |||
− | |||
− | Enjoy. |
||
− | |||
− | |||
− | |||
− | -- |
||
− | |||
− | Matous Jan Fialka [ http://vcp.ligatura.org/ ] |
||
− | |||
− | |||
− | }} |
||
− | |||
− | == Comments == |
||
− | "I really like", "we like" (without "s" on the end) and other mistakes... Sorry. Next time I will check it before I click the "add" button. |
||
− | |||
− | -- |
||
− | Matous Jan Fialka [ http://vcp.ligatura.org/ ] |
||
− | |||
− | |||
− | '''Anonymous''' |
||
− | , February 28, 2005 12:39 |
||
---- |
---- |
||
+ | I get '[GENC] is not set] [FENC is not set]' on my status line. Also the highligthing is disconcerting, it should be a solid separator line. |
||
− | If you don't like highlighting on the status line, here is a simpler version (it's just s/%[12]\?\*//g) |
||
− | let g:StatusLines{0}='[%n]%= [%03bD | %5(0x%02BH%)] [%8oC=%3{Percent()}%%] [%8c] : [%8l/%8L = %3p%%]' |
||
− | let g:StatusLines{1}='[%n]%= [GENC %10(%{GlobalEncoding()}%)] [FENC %10(%{FileEncoding()}%)]' |
||
− | let g:StatusLines{2}='[%n]%= [%F]' |
||
− | |||
− | |||
− | michal.marek--AT--matfyz.cz |
||
− | , February 28, 2005 12:57 |
||
---- |
---- |
||
+ | A bit better version is this one - works for me fine. |
||
− | I get '[GENC] is not set] [FENC is not set]' on my status line. |
||
− | Also the highligthing is disconcerting, it should be a solid |
||
− | separator line. |
||
+ | <pre> |
||
− | Jignesh Jhunjhunwala |
||
+ | let g:StatusLines{0}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%2*%03bD%* %7*|%* %2*%5(0x%02BH%)%*%7*]%* %7*[%*%3*%8oC%*%7*=%*%1*%3{Percent()}%%%*%7*]%* %7*[%*%4*%8c%*%7*]%* |
||
− | , February 28, 2005 14:40 |
||
+ | let g:StatusLines{1}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%1*ENC%* %2*%10{strlen(&enc)?&enc:"is not set"}%*%7*]%* %7*[%*%1*FENC%* %3*%10{strlen(&fenc)?&fenc:"is not set" |
||
− | ---- |
||
+ | let g:StatusLines{2}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%1*FILE%* %*%2*%t%*%7*]%*' |
||
− | A bit better version is this one - works for me fine. |
||
+ | let g:StatusLinesCurrent=-1 |
||
− | |||
− | ---cut--- |
||
− | "usage: source in ~/.vimrc |
||
− | |||
− | let g:StatusLines{0}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%2*%03bD%* %7*|%* %2*%5(0x%02BH%)%*%7*]%* %7*[%*%3*%8oC%*%7*=%*%1*%3{Percent()}%%%*%7*]%* %7*[%*%4*%8c%*%7*]%* |
||
− | let g:StatusLines{1}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%1*ENC%* %2*%10{strlen(&enc)?&enc:"is not set"}%*%7*]%* %7*[%*%1*FENC%* %3*%10{strlen(&fenc)?&fenc:"is not set" |
||
− | let g:StatusLines{2}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%1*FILE%* %*%2*%t%*%7*]%*' |
||
− | let g:StatusLinesCurrent=-1 |
||
− | |||
− | fu! SetStatusLineColors() |
||
− | hi statusline term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=white guifg=darkblue guibg=white |
||
− | hi statuslinenc term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkblue guifg=darkblue guibg=darkblue |
||
− | |||
− | hi User1 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkyellow guifg=darkblue guibg=darkyellow |
||
− | hi User2 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkcyan guifg=darkblue guibg=darkcyan |
||
− | hi User3 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkmagenta guifg=darkblue guibg=darkmagenta |
||
− | hi User4 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkgreen guifg=darkblue guibg=darkgreen |
||
− | hi User5 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkblue guifg=darkblue guibg=darkblue |
||
− | hi User6 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkred guifg=darkblue guibg=darkred |
||
− | hi User7 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=black guifg=darkblue guibg=black |
||
− | endf |
||
− | |||
− | fu! ToggleStatusLine() |
||
− | call SetStatusLineColors() |
||
− | let g:StatusLinesCurrent=g:StatusLinesCurrent+1 |
||
− | if (!exists("g:StatusLines" . g:StatusLinesCurrent)) |
||
− | let g:StatusLinesCurrent=0 |
||
− | endif |
||
− | let &statusline=g:StatusLines{g:StatusLinesCurrent} |
||
− | endf |
||
− | ---cut--- |
||
− | |||
− | Play with it. I said, that it was just for example. Use just the function and create your own statuslines. |
||
− | |||
− | -- |
||
− | Matous Jan Fialka [ http://vcp.ligatura.org/ ] |
||
− | |||
− | |||
− | |||
− | '''Anonymous''' |
||
− | , February 28, 2005 16:42 |
||
− | ---- |
||
− | You can download my version ot the above stuff here: http://pub.ligatura.org/fs/vim/vim-statuslines |
||
+ | fu! SetStatusLineColors() |
||
− | -- |
||
+ | hi statusline term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=white guifg=darkblue guibg=white |
||
− | Matous Jan Fialka [ http://vcp.ligatura.org/ ] |
||
+ | hi statuslinenc term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkblue guifg=darkblue guibg=darkblue |
||
+ | hi User1 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkyellow guifg=darkblue guibg=darkyellow |
||
+ | hi User2 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkcyan guifg=darkblue guibg=darkcyan |
||
+ | hi User3 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkmagenta guifg=darkblue guibg=darkmagenta |
||
+ | hi User4 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkgreen guifg=darkblue guibg=darkgreen |
||
+ | hi User5 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkblue guifg=darkblue guibg=darkblue |
||
+ | hi User6 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkred guifg=darkblue guibg=darkred |
||
+ | hi User7 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=black guifg=darkblue guibg=black |
||
+ | endf |
||
+ | fu! ToggleStatusLine() |
||
+ | call SetStatusLineColors() |
||
+ | let g:StatusLinesCurrent=g:StatusLinesCurrent+1 |
||
+ | if (!exists("g:StatusLines" . g:StatusLinesCurrent)) |
||
+ | let g:StatusLinesCurrent=0 |
||
+ | endif |
||
+ | let &statusline=g:StatusLines{g:StatusLinesCurrent} |
||
+ | endf |
||
+ | </pre> |
||
− | '''Anonymous''' |
||
− | , February 28, 2005 17:12 |
||
---- |
---- |
||
− | This is already builtin, see |
+ | This is already builtin, see {{help|'statusline'}}: |
+ | <pre> |
||
− | > fu! Percent() |
||
+ | fu! Percent() |
||
− | > let byte = line2byte( line( "." ) ) + col( "." ) - 1 |
||
− | + | let byte = line2byte( line( "." ) ) + col( "." ) - 1 |
|
+ | let size = (line2byte( line( "$" ) + 1 ) - 1) |
||
− | > return (byte * 100) / size |
||
+ | return (byte * 100) / size |
||
− | > endf |
||
+ | endf |
||
+ | </pre> |
||
− | Dr Dina Vora |
||
− | , March 5, 2005 15:51 |
||
---- |
---- |
||
− | <!-- parsed by vimtips.py in 0.490458 seconds--> |
Revision as of 10:07, 1 December 2007
Tip 885 Printable Monobook Previous Next
created February 28, 2005 · complexity intermediate · author Matous Jan Fialka · version 6.0
With the following code in your vimrc, you can press F3 in normal mode to switch between several different status lines.
"These three functions are just for example. "It might be that these three functions are irrelevant "in example statuslines, but they demonstrate that "functions can be used in statusline too. fu! Percent() let byte = line2byte( line( "." ) ) + col( "." ) - 1 let size = (line2byte( line( "$" ) + 1 ) - 1) return (byte * 100) / size endf fu! FileEncoding() if &fileencoding == '' return "is not set" else return &fenc endif endf fu! GlobalEncoding() if &fileencoding == '' return "is not set" else return &enc endif endf "And now the magical stuff! "We define some statuslines at first. let g:StatusLines{0}='[%1*%n%*]%= [%2*%03bD%* | %2*%5(0x%02BH%)%*] [%8oC=%1*%3{Percent()}%%%*] [%8c] : [%8l/%8L = %1*%3p%%%*]' let g:StatusLines{1}='[%1*%n%*]%= [%1*GENC%* %10(%{GlobalEncoding()}%)] [%1*FENC%* %10(%{FileEncoding()}%)]' let g:StatusLines{2}='[%1*%n%*]%= [%1*%F%*]' let g:StatusLinesCurrent=-1 "And we map switching on some unused key. map <F3> :call ToggleStatusLine()<CR> "Function that switch between several statuslines fu! ToggleStatusLine() let g:StatusLinesCurrent=g:StatusLinesCurrent+1 if (!exists("g:StatusLines" . g:StatusLinesCurrent)) let g:StatusLinesCurrent=0 endif let &statusline=g:StatusLines{g:StatusLinesCurrent} endf "We use the first one as default. call ToggleStatusLine() "Because I used some highlighting in the example statuslines "I put some highlighting definitions here too. "The colours of statusline itself. hi statusline term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=white hi statuslinenc term=inverse,bold cterm=inverse,bold ctermfg=gray ctermbg=black "Some other colours used in statuslines. hi User1 term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=yellow hi User2 term=inverse,bold cterm=inverse,bold ctermfg=darkred ctermbg=cyan
This tip should be useful if you need more information than is able to be fit in a single statusline.
Comments
If you don't like highlighting on the status line, here is a simpler version (it's just s/%[12]\?\*//g)
let g:StatusLines{0}='[%n]%= [%03bD | %5(0x%02BH%)] [%8oC=%3{Percent()}%%] [%8c] : [%8l/%8L = %3p%%]' let g:StatusLines{1}='[%n]%= [GENC %10(%{GlobalEncoding()}%)] [FENC %10(%{FileEncoding()}%)]' let g:StatusLines{2}='[%n]%= [%F]'
I get '[GENC] is not set] [FENC is not set]' on my status line. Also the highligthing is disconcerting, it should be a solid separator line.
A bit better version is this one - works for me fine.
let g:StatusLines{0}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%2*%03bD%* %7*|%* %2*%5(0x%02BH%)%*%7*]%* %7*[%*%3*%8oC%*%7*=%*%1*%3{Percent()}%%%*%7*]%* %7*[%*%4*%8c%*%7*]%* let g:StatusLines{1}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%1*ENC%* %2*%10{strlen(&enc)?&enc:"is not set"}%*%7*]%* %7*[%*%1*FENC%* %3*%10{strlen(&fenc)?&fenc:"is not set" let g:StatusLines{2}='%5* %*->%7*[%*%1*%n%*%7*]%* %= %7*[%*%1*FILE%* %*%2*%t%*%7*]%*' let g:StatusLinesCurrent=-1 fu! SetStatusLineColors() hi statusline term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=white guifg=darkblue guibg=white hi statuslinenc term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkblue guifg=darkblue guibg=darkblue hi User1 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkyellow guifg=darkblue guibg=darkyellow hi User2 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkcyan guifg=darkblue guibg=darkcyan hi User3 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkmagenta guifg=darkblue guibg=darkmagenta hi User4 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkgreen guifg=darkblue guibg=darkgreen hi User5 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkblue guifg=darkblue guibg=darkblue hi User6 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=darkred guifg=darkblue guibg=darkred hi User7 term=inverse,bold cterm=inverse,bold gui=inverse,bold ctermfg=darkblue ctermbg=black guifg=darkblue guibg=black endf fu! ToggleStatusLine() call SetStatusLineColors() let g:StatusLinesCurrent=g:StatusLinesCurrent+1 if (!exists("g:StatusLines" . g:StatusLinesCurrent)) let g:StatusLinesCurrent=0 endif let &statusline=g:StatusLines{g:StatusLinesCurrent} endf
This is already builtin, see :help 'statusline':
fu! Percent() let byte = line2byte( line( "." ) ) + col( "." ) - 1 let size = (line2byte( line( "$" ) + 1 ) - 1) return (byte * 100) / size endf