16

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.

17

[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.

| improve this answer | |
  • 1
    No, unfortunately it's listed there. I have vividchalk.vim in my ~/.vim/colors directory, and as I mentioned it loads perfectly fine as long as I type :colorscheme vividchalk in a vim session. It's just like something else overrides it, but nothing else is loaded. – Californian Dec 1 '13 at 4:37
  • 1
    And here I thought I had correctly read your question. I apologize. What does the output of ":scriptnames" show? – Heptite Dec 1 '13 at 8:23
  • No worries; thanks for taking the time to reply at all! Ah yes, and I think this is where the problem lies...so it has a bunchhh of things in there, but it's too long for this comment so I'll post it separately. On top of that, before I commented out some color thing in the synload.vim (from line 4 above), it had some error about not being able to find a colorscheme called "ansi_blows" when running :so $MYVIMRC. Any ideas which file I should investigate further? – Californian Dec 1 '13 at 9:40
  • 1
    @Heptite There are a lot of things that are run before and after my ~/.vimrc it seems. Is there a way to just instruct that my ~/.vimrc is run last, so that that it'll overwrite whatever has happened before that? – dreamer Sep 13 '17 at 14:05
  • 1
    In my case, my mistake was putting colorscheme ... before set t_Co=256 and causing the problem. – nima Apr 29 '19 at 8:22
10

set background=dark should be before syntax enable and colorscheme whatever in your .vimrc

| improve this answer | |
  • 2
    Accurate, but the problem was found with the above answer. Thank you though; hopefully someone will find this useful. – Californian Nov 19 '14 at 21:16
  • This fixed it for me after looking through all scripts. Thanks! (Just can't wait for neovim...). – Ben Aug 17 '16 at 8:14
7

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:

enter image description here

Also, as of recently nvim has deprecated NVIM_TUI_ENABLE_TRUE_COLOR in favor of set termguicolors (see this).

| improve this answer | |
1

.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.

| improve this answer | |
0

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.vim

to .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.
| improve this answer | |
0

In my case I use color schemes from plugins (external repositories). So I have to load plugins before applying colorscheme command.

| improve this answer | |
0

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.

| improve this answer | |
0

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.

| improve this answer | |

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.