How can I change vim status line color?
Asked Answered
L

3

55

I'm tring to change vim's status line color by editing my .vimrc .

By using the command au, I tried to change the color of the status line when entering or leaving insert mode; by using this command nothing happens:

hi StatusLine guibg=whatevercolourIwant

By changing the status line color directly, without any au command, the background remains the same.

Is there reason why by executing

:hi StatusLine guibg=red,

for instance, the background of the status bar still remains greenish?

Longdrawnout answered 30/1, 2012 at 15:4 Comment(0)
S
58

if you are running vim in terminal, try:

hi StatusLine ctermbg=whatever ctermfg=whatever

guibg guifg are for GUI.

hope it helps.

Searby answered 30/1, 2012 at 15:13 Comment(1)
To change the status line color of a window that is not in focus use StatusLineNCMueller
M
35

I use this for my status line, which changes the colour of the line depending on what mode I'm in, amongst other tidbits:

function! InsertStatuslineColor(mode)
  if a:mode == 'i'
    hi statusline guibg=Cyan ctermfg=6 guifg=Black ctermbg=0
  elseif a:mode == 'r'
    hi statusline guibg=Purple ctermfg=5 guifg=Black ctermbg=0
  else
    hi statusline guibg=DarkRed ctermfg=1 guifg=Black ctermbg=0
  endif
endfunction

au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline guibg=DarkGrey ctermfg=8 guifg=White ctermbg=15

" default the statusline to green when entering Vim
hi statusline guibg=DarkGrey ctermfg=8 guifg=White ctermbg=15

" Formats the statusline
set statusline=%f                           " file name
set statusline+=[%{strlen(&fenc)?&fenc:'none'}, "file encoding
set statusline+=%{&ff}] "file format
set statusline+=%y      "filetype
set statusline+=%h      "help file flag
set statusline+=%m      "modified flag
set statusline+=%r      "read only flag

" Puts in the current git status
    if count(g:pathogen_disabled, 'Fugitive') < 1   
        set statusline+=%{fugitive#statusline()}
    endif

" Puts in syntastic warnings
    if count(g:pathogen_disabled, 'Syntastic') < 1  
        set statusline+=%#warningmsg#
        set statusline+=%{SyntasticStatuslineFlag()}
        set statusline+=%*
    endif

set statusline+=\ %=                        " align left
set statusline+=Line:%l/%L[%p%%]            " line X of Y [percent of file]
set statusline+=\ Col:%c                    " current column
set statusline+=\ Buf:%n                    " Buffer number
set statusline+=\ [%b][0x%B]\               " ASCII and byte code under cursor
Mccarty answered 2/2, 2012 at 22:38 Comment(3)
So to use this configuration in vim it has to be pasted in the .vimrc file?Northumberland
yes a similar info is in vim.wikia.com/wiki/…Cobia
Putting it in, I get Undefined variable: g:pathogen_disabledParticularism
O
5

This is indeed a awesome bit of code!!

I have modified it to suit my needs. I have added some wording to my buffer state:

[saved] or [modified].

I set my status bar color based on buffer change event. DarkSlateGray for unchanged/normal. OrangeRed4 if there were any modifications done.

Here is my modified code:

" Some funky status bar code its seems
" https://mcmap.net/q/333716/-how-can-i-change-vim-status-line-color
set laststatus=2            " set the bottom status bar

function! ModifiedColor()
    if &mod == 1
        hi statusline guibg=White ctermfg=8 guifg=OrangeRed4 ctermbg=15
    else
        hi statusline guibg=White ctermfg=8 guifg=DarkSlateGray ctermbg=15
    endif
endfunction

au InsertLeave,InsertEnter,BufWritePost   * call ModifiedColor()
" default the statusline when entering Vim
hi statusline guibg=White ctermfg=8 guifg=DarkSlateGray ctermbg=15

" Formats the statusline
set statusline=%f                           " file name
set statusline+=[%{strlen(&fenc)?&fenc:'none'}, "file encoding
set statusline+=%{&ff}] "file format
set statusline+=%y      "filetype
set statusline+=%h      "help file flag
set statusline+=[%{getbufvar(bufnr('%'),'&mod')?'modified':'saved'}]      
"modified flag

set statusline+=%r      "read only flag

set statusline+=\ %=                        " align left
set statusline+=Line:%l/%L[%p%%]            " line X of Y [percent of file]
set statusline+=\ Col:%c                    " current column
set statusline+=\ Buf:%n                    " Buffer number
set statusline+=\ [%b][0x%B]\               " ASCII and byte code under cursor
Outmoded answered 5/12, 2017 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.