Skip to content

Instantly share code, notes, and snippets.

@meskarune
Last active September 18, 2024 03:24
Show Gist options
  • Save meskarune/57b613907ebd1df67eb7bdb83c6e6641 to your computer and use it in GitHub Desktop.
Save meskarune/57b613907ebd1df67eb7bdb83c6e6641 to your computer and use it in GitHub Desktop.
simple functional vim status line - jellybeans theme colors
" status bar colors
au InsertEnter * hi statusline guifg=black guibg=#d7afff ctermfg=black ctermbg=magenta
au InsertLeave * hi statusline guifg=black guibg=#8fbfdc ctermfg=black ctermbg=cyan
hi statusline guifg=black guibg=#8fbfdc ctermfg=black ctermbg=cyan
" Status line
" default: set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)
" Status Line Custom
let g:currentmode={
\ 'n' : 'Normal',
\ 'no' : 'Normal·Operator Pending',
\ 'v' : 'Visual',
\ 'V' : 'V·Line',
\ '^V' : 'V·Block',
\ 's' : 'Select',
\ 'S' : 'S·Line',
\ '^S' : 'S·Block',
\ 'i' : 'Insert',
\ 'R' : 'Replace',
\ 'Rv' : 'V·Replace',
\ 'c' : 'Command',
\ 'cv' : 'Vim Ex',
\ 'ce' : 'Ex',
\ 'r' : 'Prompt',
\ 'rm' : 'More',
\ 'r?' : 'Confirm',
\ '!' : 'Shell',
\ 't' : 'Terminal'
\}
set laststatus=2
set noshowmode
set statusline=
set statusline+=%0*\ %n\ " Buffer number
set statusline+=%1*\ %<%F%m%r%h%w\ " File path, modified, readonly, helpfile, preview
set statusline+=%3*│ " Separator
set statusline+=%2*\ %Y\ " FileType
set statusline+=%3*│ " Separator
set statusline+=%2*\ %{''.(&fenc!=''?&fenc:&enc).''} " Encoding
set statusline+=\ (%{&ff}) " FileFormat (dos/unix..)
set statusline+=%= " Right Side
set statusline+=%2*\ col:\ %02v\ " Colomn number
set statusline+=%3*│ " Separator
set statusline+=%1*\ ln:\ %02l/%L\ (%3p%%)\ " Line number / total lines, percentage of document
set statusline+=%0*\ %{toupper(g:currentmode[mode()])}\ " The current mode
hi User1 ctermfg=007 ctermbg=239 guibg=#4e4e4e guifg=#adadad
hi User2 ctermfg=007 ctermbg=236 guibg=#303030 guifg=#adadad
hi User3 ctermfg=236 ctermbg=236 guibg=#303030 guifg=#303030
hi User4 ctermfg=239 ctermbg=239 guibg=#4e4e4e guifg=#4e4e4e
@lemon-clown
Copy link

hey, how to make the colors working?

@nubilfi
Copy link

nubilfi commented Jan 1, 2019

Hi, thanks for the statusline config.
But i have an issue, i keep getting error key not present in dictionary for this dictionary \ '^V' : 'V·Block'

It should be fixed with the following changes:

" Function: return current mode
" abort -> function will abort soon as error detected
function! ModeCurrent() abort
    let l:modecurrent = mode()
    " use get() -> fails safely, since ^V doesn't seem to register
    " 3rd arg is used when return of mode() == 0, which is case with ^V
    " thus, ^V fails -> returns 0 -> replaced with 'V Block'
    let l:modelist = toupper(get(g:currentmode, l:modecurrent, 'V·Block '))
    let l:current_status_mode = l:modelist
    return l:current_status_mode
endfunction

" set statusline+=%0*\ %{toupper(g:currentmode[mode()])}\ 
" ======== replace with the following one =========
set statusline+=%0*\ %{ModeCurrent()}\ 

@cl1pp0
Copy link

cl1pp0 commented Apr 19, 2020

This worked for me:

'\<C-V>' -- is a literal string in VimL.
You must use double quotes to make the substitution work: "\<C-V>".

See:
https://stackoverflow.com/questions/56274737/what-is-the-return-value-for-visual-block-mode-in-vimscript

@riordant
Copy link

Awesome, thank you

@fabianmolinab
Copy link

Nice, very good :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment