liuchengxu / vim-better-default

:art: Simplify your .vimrc and make the default vim better
MIT License
158 stars 37 forks source link

A better statusline for vim without any plugins needed, build up from scratch #7

Closed liuchengxu closed 7 years ago

liuchengxu commented 7 years ago

I extract the default statusline part from space-vim, which can bring you a very beautiful statusline. I don't think it is appropriate to incorporate it into vim-better-default, so just leave it here.

You can add the following content to your .vimrc, or modify it for your own needs and preference. The example is self-explanatory. Here is 256 color chart, which could assist you in decorating the statusline.

function! Buf_total_num()
    return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
function! File_size(f)
    let l:size = getfsize(expand(a:f))
    if l:size == 0 || l:size == -1 || l:size == -2
        return ''
    endif
    if l:size < 1024
        return l:size.' bytes'
    elseif l:size < 1024*1024
        return printf('%.1f', l:size/1024.0).'k'
    elseif l:size < 1024*1024*1024
        return printf('%.1f', l:size/1024.0/1024.0) . 'm'
    else
        return printf('%.1f', l:size/1024.0/1024.0/1024.0) . 'g'
    endif
endfunction
" [B-buffer number]
set statusline=%1*[B-%n]%*
" TOT is an abbreviation for total, [TOT:total buffer number]
set statusline+=%2*[TOT:%{Buf_total_num()}]%*
" File size
set statusline+=%3*\ %{File_size(@%)}\ %*
" full path
set statusline+=%<%4*\ %F\ %*
set statusline+=%5*\ %{exists('g:loaded_ale')?ALEGetStatusLine():''}%*
set statusline+=%6*\ %{exists('g:loaded_fugitive')?fugitive#statusline():''}%*
set statusline+=%7*\ %m%r%y\ %*
set statusline+=%=%8*\ %{&ff}\ \|\ %{\"\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"\ \|\"}\ %-10.(%l:%c%V%)%*
set statusline+=%9*\ %P\ %*

" default bg for statusline is 236 in space-vim-dark
hi User1 cterm=bold ctermfg=232 ctermbg=179
hi User2 cterm=None ctermfg=214 ctermbg=242
hi User3 cterm=None ctermfg=251 ctermbg=240
hi User4 cterm=bold ctermfg=169 ctermbg=239
hi User5 cterm=None ctermfg=208 ctermbg=238
hi User6 cterm=None ctermfg=178 ctermbg=237
hi User7 cterm=None ctermfg=250 ctermbg=237
hi User8 cterm=None ctermfg=249 ctermbg=238
hi User9 cterm=None ctermfg=249 ctermbg=240

UPDATE: it has been separated out: eleline.vim