Reputation: 331
I was hoping to see if I could change the background color of Vim, so that when I'm insert mode my background changes slightly. (my default is dark grey, i'm hoping to change to light grey).
I was following some other SO posts I found, and tried
autocmd InsertEnter * hi Normal ctermbg=darkgrey
autocmd InsertEnter * hi Normal ctermbg=none
That was slightly working, since it would change my background, but it also changed my text color too - I just want the background changed.
I tried adding in ctermfg (foreground?)
autocmd InsertEnter * hi Normal ctermfg=none ctermbg=darkgrey
autocmd InsertEnter * hi Normal ctermfg=none ctermbg=none
Still did not fix it.
Pictures for reference:
When I open up vi - Default colors - which I like - Command mode
When I go into "insert" mode (background subtly changes (good!) text changes (not what I wanted)
I google'd some more, and found another SO post, that was explaining how the way ctermbg works, is it doesn't just change the background color, instead use
set background=
I tried that too:
autocmd InsertEnter * set background=dark
autocmd InsertLeave * set background=light
It changes the font color and background color, but this time when I go back to command mode the font color is back to normal (along with the background).
Is it possible, to just change the background color between 2 color (light grey and dark grey) without affecting text color, going from Insert Mode to Command Mode?
Upvotes: 4
Views: 9158
Reputation: 8497
Is it possible, to just change the background color between 2 color (light grey and dark grey) without affecting text color, going from Insert Mode to Command Mode?
The answer is yes!
The trick consists in using GUI colors directly (like GVim) instead of terminal ones. Please try this:
set termguicolors
before setting the colorscheme in your .vimrc
autocmd InsertEnter * hi Normal guibg=#4D4D4D
autocmd InsertLeave * hi Normal guibg=#333333
If your terminal is compatible and your Vim distribution is up-to-date, it should work.
If you like dark Vim colorschemes, you might be interested in Archery. I have shared the project on GitHub: https://github.com/Badacadabra/vim-archery
Upvotes: 4