如何更改vim状态行颜色?

时间:2012-01-30 15:04:32

标签: vim background-color statusbar

我想通过编辑我的.vimrc来改变vim的状态行颜色。

使用命令au,我尝试在进入或退出插入模式时更改状态行的颜色;通过使用此命令没有任何反应:

hi StatusLine guibg=whatevercolourIwant

通过直接更改状态行颜色,不使用任何au命令,背景保持不变。

是否有理由通过执行

:hi StatusLine guibg=red

例如,状态栏的背景仍然是绿色的?

3 个答案:

答案 0 :(得分:42)

如果您在终端中运行vim,请尝试:

hi StatusLine ctermbg=whatever ctermfg=whatever

guibg guifg用于GUI。

希望它有所帮助。

答案 1 :(得分:34)

我将它用于我的状态行,根据我所处的模式以及其他花絮改变行的颜色:

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

答案 2 :(得分:1)

这确实是一个很棒的代码!!

我已修改它以满足我的需要。我在缓冲区状态中添加了一些措辞:

[已保存]或[已修改]。

我根据缓冲区更改事件设置状态栏颜色。 DarkSlateGray保持不变/正常。 OrangeRed4如果有任何修改。

这是我修改后的代码:

" Some funky status bar code its seems
" https://stackoverflow.com/questions/9065941/how-can-i-change-vim-status-line-colour
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