Last active
March 17, 2019 03:53
-
-
Save meskarune/16bea6c432730bc219efde97d0835c34 to your computer and use it in GitHub Desktop.
vim statusline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Status line | |
" default: set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%) | |
" Warning for trailing spaces | |
function! StatuslineTrailingSpaceWarning() | |
if !exists("b:statusline_trailing_space_warning") | |
if search('\s\+$', 'nw') != 0 | |
let b:statusline_trailing_space_warning = '§ ' | |
else | |
let b:statusline_trailing_space_warning = '' | |
endif | |
endif | |
return b:statusline_trailing_space_warning | |
endfunction | |
" Status Line Custom Mode | |
let g:mode_hl = { | |
\ 'n' : ['Normal', 'Normal'], 'no' : ['Normal', 'N·Operator Pending'], | |
\ 'v' : ['Visual', 'Visual'], 'V' : ['Visual', 'V·Line'], | |
\ "\<c-v>" : ['Visual', 'V·Block'], 's' : ['Visual', 'Select'], | |
\ 'S' : ['Visual', 'S·Line'], "\<c-s>" : ['Visual', 'S·Block'], | |
\ 'i' : ['Insert', 'Insert'], 'ic' : ['Insert', 'I·Compl'], | |
\ 'ix' : ['Insert', 'I·X Compl'], 'R' : ['Replace', 'Replace'], | |
\ 'Rc' : ['Replace', 'R·Compl'], 'Rv' : ['Replace', 'R·Virtual'], | |
\ 'Rx' : ['Replace', 'R·X Compl'], 'c' : ['Command','Command'], | |
\ 'cv' : ['Term','Vim Ex'], 'ce' : ['Term','Ex'], | |
\ 'r' : ['Prompt','Prompt'], 'rm' : ['Prompt','More'], | |
\ 'r?' : ['Prompt','Confirm'], '!' : ['Term','Shell'], | |
\ 't' : ['Term','Terminal']} | |
let s:ins = {'i':'i', 'r':'R','v':'Rv'} | |
" Colors are [gui , cterm] | |
let s:pallet = { | |
\ 'Normal' : ['#8197bf', '4'], 'Insert' : ['#72a25a', '2'], | |
\ 'Visual' : ['#d8ad4c', '3'], 'Replace' : ['#d75f5f', '1'], | |
\ 'Command' : ['#8fbfdc', '14'], 'Prompt' : ['#d7afff', '5'], | |
\ 'Term' : ['#adadad', '7']} | |
let s:modecache = '' | |
function! ChangeColor() | |
let s:hlmode = g:mode_hl[mode()][0] | |
if s:modecache == s:hlmode | |
return '' | |
endif | |
let s:modecache = s:hlmode | |
let [s:color1, s:color2] = s:pallet[s:hlmode] | |
let s:mode_color = printf(' guifg=#1c1c1c guibg=%s ctermfg=234 ctermbg=%s', s:color1, s:color2) | |
let s:accent_color = printf(' guifg=%s guibg=#1c1c1c ctermfg=%s ctermbg=234', s:color1, s:color2) | |
execute 'highlight StlMode'.s:mode_color | |
execute 'highlight StlText'.s:accent_color | |
return '' | |
endfunction | |
augroup Statusline | |
autocmd! | |
autocmd CursorHold,InsertLeave,BufWritePost * unlet! b:statusline_trailing_space_warning | |
autocmd VimEnter * call ChangeColor() | |
augroup end | |
hi statusline gui=bold ctermfg=234 ctermbg=7 guibg=#adadad guifg=#1c1c1c | |
hi StlText guifg=#adadad guibg=#1c1c1c ctermfg=7 ctermbg=234 | |
hi statuslinenc gui=bold guifg=#adadad guibg=#1c1c1c ctermfg=007 ctermbg=234 | |
hi User1 ctermfg=007 ctermbg=237 guibg=#4a4a4a guifg=#adadad | |
hi User2 ctermfg=001 ctermbg=234 guibg=#1c1c1c guifg=#d75f5f | |
hi User3 ctermfg=011 ctermbg=234 guibg=#1c1c1c guifg=#fad07a | |
set laststatus=2 | |
set noshowmode | |
set statusline= | |
set statusline+=%*%{ChangeColor()} | |
set statusline+=%#StlMode#\ %{g:mode_hl[mode()][1]}\ " The current mode | |
set statusline+=%1*\ %Y\ " FileType | |
set statusline+=%#StlText#\ %<%F\ " File path | |
set statusline+=%2*%M\ " Modified | |
set statusline+=%2*%{&readonly?'\ RO\ ':''} " Readonly | |
set statusline+=%3*%{StatuslineTrailingSpaceWarning()} " Space warning | |
set statusline+=%3*%{&paste?'\ Paste\ ':''} " Paste mode | |
set statusline+=%2*%{&spell?'\ Spell\ ':''} " Spell check | |
set statusline+=%= " Right Side | |
set statusline+=%3*%w\ " Preview | |
set statusline+=%#StlText#\ %{''.(&fenc!=''?&fenc:&enc).''} " Encoding | |
set statusline+=\ [%{&ff}]\ " FileFormat | |
set statusline+=%1*\ col:\ %-02v\ " Column number | |
set statusline+=%#StlMode#\ ≡\ %-03l/%L\ %3p%%\ " See next line | |
" Line number / total lines, percentage of document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment