tirenweb
tirenweb

Reputation: 31749

vim: change the status line color in insert mode

I found this snippet to change the status line color when i go to insert mode:

" first, enable status line always
set laststatus=2

" now set it up to change the status line based on mode
if version >= 700
  au InsertEnter * hi StatusLine term=reverse ctermbg=5 gui=undercurl guisp=Magenta
  au InsertLeave * hi StatusLine term=reverse ctermfg=0 ctermbg=2 gui=bold,reverse
endif

Now, when i go to insert mode the status line go to violet color, but I want to change it to go to red color. I changed Magenta by Red, but it doesn't work..

Upvotes: 5

Views: 5200

Answers (4)

casonadams
casonadams

Reputation: 1200

Neovim

See nvim_set_hl() for all options.

vim.cmd("colorscheme walh-gruvbox") -- set colorscheme

local insertCallBack = function()
  vim.api.nvim_set_hl(0, "StatusLine", { ctermfg = 0, ctermbg = 12 })
end

local NormalCallBack = function()
  vim.api.nvim_set_hl(0, "StatusLine", { ctermfg = "NONE", ctermbg = 0 })
end

vim.api.nvim_create_autocmd({ "InsertEnter" }, {
  pattern = "*",
  callback = insertCallBack,
})

vim.api.nvim_create_autocmd({ "InsertLeave" }, {
  pattern = "*",
  callback = NormalCallBack,
})

NormalMode InsertMode

Upvotes: 0

SergioAraujo
SergioAraujo

Reputation: 11830

Great solution: Powerline plugin

Normal mode Insert mode

Upvotes: 1

vim_commando
vim_commando

Reputation: 96

I don't see any mention of whether you are using a gui version of Vim, or just Vim in a terminal.

If you are in a terminal you need to change "ctermbg=5" to "ctermbg=red" instead. In this case "5" translates to "DarkMagenta". Vim will accept numbers or color names for these attributes.

More information can be found in under sections 2 and 3 under the Highlight Command from the Vim Syntax Documentation.

Upvotes: 4

voithos
voithos

Reputation: 70632

If you use :help, you can find out what each of those attributes mean.

guisp is used for the "special" color of the highlight. In this case, it's the color of the undercurl effect. It sounds like you want to change the actual highlight color, so try this:

au InsertEnter * hi StatusLine term=reverse ctermbg=5 gui=undercurl guisp=Magenta guibg=Red

And in fact, if you just use a GUI Vim, you don't need any of the terminal options:

au InsertEnter * hi StatusLine guibg=Red
au InsertLeave * hi StatusLine guibg=#ccdc90

For InsertLeave, I just used the my normal StatusLine color as an example. You should be able to find it in your colorscheme file.

Incidentally, guibg actually affects the text color, while guifg affect the line color...

Upvotes: 4

Related Questions