Last active
September 13, 2022 13:15
-
-
Save ahmedelgabri/b9127dfe36ba86f4496c8c28eb65ef2b to your computer and use it in GitHub Desktop.
Trying to build my vim statusline without plugins
This file contains 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
" Statusline & Tabline/Buffer line | |
" Dynamically getting the fg/bg colors from the current colorscheme, returns hex which is enough for me to use in Neovim | |
" Needs to figure out how to return cterm values too | |
let fgcolor=synIDattr(synIDtrans(hlID("Normal")), "fg", "gui") | |
let bgcolor=synIDattr(synIDtrans(hlID("Normal")), "bg", "gui") | |
" Tabline/Buffer line | |
set showtabline=2 | |
set tabline="%1T" | |
" Statusline | |
" https://github.com/Greduan/dotfiles/blob/76e16dd8a04501db29989824af512c453550591d/vim/after/plugin/statusline.vim | |
let g:currentmode={ | |
\ 'n' : 'N ', | |
\ 'no' : 'N·Operator Pending ', | |
\ 'v' : 'V ', | |
\ 'V' : 'V·Line ', | |
\ 'x22' : 'V·Block ', | |
\ 's' : 'Select ', | |
\ 'S' : 'S·Line ', | |
\ 'x19' : 'S·Block ', | |
\ 'i' : 'I ', | |
\ 'R' : 'R ', | |
\ 'Rv' : 'V·Replace ', | |
\ 'c' : 'Command ', | |
\ 'cv' : 'Vim Ex ', | |
\ 'ce' : 'Ex ', | |
\ 'r' : 'Prompt ', | |
\ 'rm' : 'More ', | |
\ 'r?' : 'Confirm ', | |
\ '!' : 'Shell ', | |
\ 't' : 'Terminal ' | |
\} | |
highlight User1 cterm=None gui=None ctermfg=007 guifg=fgcolor | |
highlight User2 cterm=None gui=None ctermfg=008 guifg=bgcolor | |
highlight User3 cterm=None gui=None ctermfg=008 guifg=bgcolor | |
highlight User4 cterm=None gui=None ctermfg=008 guifg=bgcolor | |
highlight User5 cterm=None gui=None ctermfg=008 guifg=bgcolor | |
highlight User7 cterm=None gui=None ctermfg=008 guifg=bgcolor | |
highlight User8 cterm=None gui=None ctermfg=008 guifg=bgcolor | |
highlight User9 cterm=None gui=None ctermfg=007 guifg=fgcolor | |
" Automatically change the statusline color depending on mode | |
function! ChangeStatuslineColor() | |
if (mode() =~# '\v(n|no)') | |
exe 'hi! StatusLine ctermfg=008 guifg=fgcolor gui=None cterm=None' | |
elseif (mode() =~# '\v(v|V)' || g:currentmode[mode()] ==# 'V·Block' || get(g:currentmode, mode(), '') ==# 't') | |
exe 'hi! StatusLine ctermfg=005 guifg=#00ff00 gui=None cterm=None' | |
elseif (mode() ==# 'i') | |
exe 'hi! StatusLine ctermfg=004 guifg=#6CBCE8 gui=None cterm=None' | |
else | |
exe 'hi! StatusLine ctermfg=006 guifg=orange gui=None cterm=None' | |
endif | |
return '' | |
endfunction | |
" Find out current buffer's size and output it. | |
function! FileSize() | |
let bytes = getfsize(expand('%:p')) | |
if (bytes >= 1024) | |
let kbytes = bytes / 1024 | |
endif | |
if (exists('kbytes') && kbytes >= 1000) | |
let mbytes = kbytes / 1000 | |
endif | |
if bytes <= 0 | |
return '0' | |
endif | |
if (exists('mbytes')) | |
return mbytes . 'MB ' | |
elseif (exists('kbytes')) | |
return kbytes . 'KB ' | |
else | |
return bytes . 'B ' | |
endif | |
endfunction | |
function! ReadOnly() | |
if &readonly || !&modifiable | |
return '' | |
else | |
return '' | |
endfunction | |
function! GitInfo() | |
let git = fugitive#head() | |
if git != '' | |
return ' '.fugitive#head() | |
else | |
return '' | |
endfunction | |
" http://stackoverflow.com/a/10416234/213124 | |
set laststatus=2 | |
set statusline= | |
set statusline+=%{ChangeStatuslineColor()} " Changing the statusline color | |
set statusline+=%0*\ %{toupper(g:currentmode[mode()])} " Current mode | |
set statusline+=%8*\ [%n] " buffernr | |
set statusline+=%8*\ %{GitInfo()} " Git Branch name requires https://github.com/tpope/vim-fugitive | |
set statusline+=%8*\ %<%F\ %{ReadOnly()}\ %m\ %w\ " File+path | |
set statusline+=%* | |
set statusline+=%9*\ %= " Space | |
set statusline+=%8*\ %y\ " FileType | |
set statusline+=%7*\ %{(&fenc!=''?&fenc:&enc)}\[%{&ff}]\ " Encoding & Fileformat | |
set statusline+=%8*\ %-3(%{FileSize()}%) " File size | |
set statusline+=%0*\ %3p%%\ \ %l:\ %3c\ " Rownumber/total (%) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could also use something like: