I've looked through a bunch of questions here, and I'm pretty experienced with Vim, but for some reason my .vimrc isn't setting the colorscheme any more.
I don't know when this started, but I just moved to a new machine and it's rather baffling to me. The oddest part is I'm able to set it manually :colorscheme vividchalk, it just won't work when I have colorscheme vividchalk in .vimrc. I tried commenting out absolutely everything else in my .vimrc, still no luck. Tried commenting out everything but syntax on and set t_Co=256, still no luck (and same behavior of manual settings working).
Any ideas? My setup is ssh-ing into my Ubuntu computer from Chrome OS.
8 Answers
[Answer completely revised for others.]
Since the ":colorscheme" command works manually it proves you have the colorscheme installed. This means you somehow have something coming after it in your initialization scripts that is overriding your preferred scheme. You can track this down by typing ":scriptnames" and reading through it for another colorscheme being loaded. Once you find it, you can remove or comment out that line in whatever initialization script it is being called from.
set background=dark should be before syntax enable and colorscheme whatever in your .vimrc
For others like me stumbling in:
If you are using vim or nvim inside a terminal emulator, make sure that the colors settings for your profile are right. For gnome-terminal, I had to disable "use colors from system theme" in my Preferences/Profile/Color settings before I could get my colorscheme to properly work:
Also, as of recently nvim has deprecated NVIM_TUI_ENABLE_TRUE_COLOR in favor of set termguicolors (see this).
In my case I use color schemes from plugins (external repositories). So I have to load plugins before applying colorscheme command.
.gvimrc
When using gvim, it may be necessary to put colorscheme vividchalk also in the .gvimrc file, despite this already being present in .vimrc
:scriptnames may reveal when a default colorscheme like /usr/share/vim/vim80/colors/ron.vim is being loaded.
In my case, I just duplicated an existing theme, delek.vim, and renamed it to mydelek.vim and changed a few colors. However, colorscheme mydelek in .vimrc would still load delek.vim.
Then I figured out I also need to change this line inside mydelek.vim:
let g:colors_name = "delek"to:
let g:colors_name = "mydelek"After that mydelek was properly loaded instead of delek. Hope this helps somebody who is also just tweaking an existing theme.
Had the same issue and my problem was putting the
call plug#end()at the end of the .vimrc file instead of right after the plugin list. Posting it here, so it may help someone finding this thread via search engine.
I had same problem on Debian stretch, also with some other commands (color and set background work manually but not in .vimrc). But I didn't want to look through every file in scriptnames.
Solution is to add
source $VIMRUNTIME/defaults.vimto .vimrc
This line can be found in /usr/share/vim/vimXX/vimrc_example.vim for reference (XX is vim version, in my case 80).
I suppose defaults.vim does some configuration stuff necessary for changing the color. But defaults.vim is not loaded if the user has a ~/.vimrc, according to /usr/share/vim/vimrc
" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.