2

I want my vim statusline to have some color and I can't figure out why it does not with this code:

set laststatus=2
set statusline+=%1*\ %f\ %*
set statusline+=%2*\ %<%F%*
set statusline+=%2*%m%*
set statusline+=%=
set statusline+=%1*%=%5l%*
set statusline+=%2*/%L%*
hi User1 guifg=#eea040 guibg=%222222
hi User2 guifg=%dd3333 guibg=%222222

This is what it looks like currently: Vim Image

How can I

  1. Get color onto the filename etc. and
  2. Remove the whitespace between the left and right side?

Thank You in advance.

1

according to :h gui-colors

    You can also specify a color by its Red, Green and Blue values.
    The format is "#rrggbb", where
        "rr"    is the Red value
        "gg"    is the Green value
        "bb"    is the Blue value
    All values are hexadecimal, range from "00" to "ff".  Examples: >
  :highlight Comment guifg=#11f0c3 guibg=#ff00ff

You need to change guibg=%222222 to guibg=#222222. It surprises me you didn't get any error, i thought you are running a terminal vim until i saw gvim tag.

You can remove %= area by changing guifg of StatusLine to guibg of your User#.

To fix problem 1:

hi User1 guifg=#eea040 guibg=#222222
hi User2 guifg=#dd3333 guibg=#222222

To fix problem 2:

    hi StatusLine guifg=#222222
  • You can use :h gui-colors in terminal vim as well as gui vim. Check out :h termguicolors – klaus Apr 15 at 6:42
0

You need these lines. Put them in your vimrc and restart vim (:xa and $ vim). Or you can put them in your vimrc and source it (:so %) twice, once to get the vimrc updated and once again to set up the colors according to the :h autocmd.

set termguicolors
set laststatus=2
set statusline=%1*\ %f\ %*
set statusline+=%2*\ %<%F%*
set statusline+=%2*%m%*
set statusline+=%=
set statusline+=%1*%=%5l%*
set statusline+=%2*/%L%*

augroup statusline
    autocmd!
    autocmd VimEnter,ColorScheme * hi User1 guifg=#eea040 guibg=#222222
    autocmd VimEnter,ColorScheme * hi User2 guifg=#dd3333 guibg=#222222
augroup END

Explanation:

  • The :h termguicolors part is just there in case you're using a terminal vim.

  • I took the liberty to change the += from the first line to = because otherwise everytime you sourced your vimrc you would've added to (not overwritten) your statusline.

  • You need to wrap the :h hi commands in :h :augroup. Otherwise, it won't work when you manually change the colorscheme with :colorscheme default etc.
  • You had some typos. You used % instead of # to represent hex colors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.