This is my statusline
setting:
:set laststatus=2
:set statusline=%{GetMode()}\ %n\ %#StatusLineY#%m%*\%#StatusLineR#%r%*\ %t\ [%o\ %l\,%c\ %p%%\]
and this is the GetMode() functiom
function! GetMode()
let ms=mode()
if ms == 'n'
return 'NORMAL '
elseif ms == 'i'
return 'INSERT '
elseif ms == 'v' || ms == 'V'
return 'VISUAL '
elseif ms == 's' || ms == 'S'
return 'SELECT '
elseif ms == 'R' || ms == 'Rv'
return 'REPLACE'
elseif ms == '!'
return 'SHELL '
endif
endfunction
This setting works well and now I would like to have different colors for the stringsreturned by GetMode()
function (and not the whole statusline).
EDIT2 So for example blue foreground color for 'NORMAL', yellow for 'INSERT' etc. Is it possible to achieve this ? If so, how ?
EDIT1
According to comments given below, I tried to add the autogroup statusline
as follows:
augroup statusline
autocmd!
autocmd VimEnter,ColorScheme * hi User1 guibg=#0a0a0a guifg=#0000ff
augroup END
and applying this small change to GetMode
:
let ms=mode()
if ms == 'n'
return %1*NORMAL\ %*
But this generates an E15 INvalid expression error.
:h statusline
and:h hl-User1..9
. Read the whole parts of:h statusline
, everything is there.GetMode
function to return the highlighted function according to that but it doesn't work.%1*
in theset statusline
part. It doesn't have any meaning otherwise. In my example in the link, you can see, I used%1*
and%2*
in the ex-commandset statusline
as it is suggested in:h statusline
. That is to say, useset stl=%1*%{get_mode()}%0*