Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocmd background resets colorscheme to default #2

Closed
tomvanderlee opened this issue Feb 14, 2016 · 4 comments
Closed

Autocmd background resets colorscheme to default #2

tomvanderlee opened this issue Feb 14, 2016 · 4 comments

Comments

@tomvanderlee
Copy link

I use vim in a terminal emulator and as suggested in the readme I have this in my vimrc

autocmd ColorScheme janah highlight Normal ctermbg=235
colorscheme janah

One problem though, it sets the background correctly but it resets the colorscheme to the default colorscheme.

If i do :colorscheme janah it works properly though.

Any idea why and how to fix it?

@mhinz
Copy link
Owner

mhinz commented Feb 14, 2016

What's the output of :echo colors_name after starting?

Vim or Neovim? I see that you use &t_Co in your vimrc, but Neovim doesn't have these options anymore. Maybe it's throwing an error that gets caught and thus it sets desert instead?

@tomvanderlee
Copy link
Author

What's the output of :echo colors_name after starting?

Both in vim and neovim i get

E121: Undefined variable: colors_name
E15: Invalid expression: colors_name

Vim or Neovim? I see that you use &t_Co in your vimrc, but Neovim doesn't have these options anymore. Maybe it's throwing an error that gets caught and thus it sets desert instead?

You are talking about this snippet?

try
    if (&t_Co == 256) && match($TERM, "256color") >= 0
        autocmd ColorScheme janah highlight Normal ctermbg=235
        colorscheme janah
    else
        throw "nocolor"
    endif
catch
    colorscheme desert
endtry

I know it executes the if (&t_Co == 256) && match($TERM, "256color") >= 0-block because the background color gets set correctly, but the colorscheme itself is set to default. it is also not falling back to desert, because the output of :colorscheme is default.

it is really weird and even if I do

 autocmd ColorScheme janah highlight Normal ctermbg=235
 colorscheme janah

without the fancy try-catch stuff the colorscheme is still set to default, but the background color is as expected

@mhinz
Copy link
Owner

mhinz commented Feb 15, 2016

Actually I think you're hitting one of the many highlighting bugs of Vim. In your case it gets triggered by setting 'background' after the :autocmd.

Doesn't work:

colorscheme janah
autocmd ColorScheme janah highlight Normal ctermbg=235
set background=dark

Does work:

colorscheme janah
set background=dark
autocmd ColorScheme janah highlight Normal ctermbg=235

There's no way I can fix this from the colorscheme itself, but I could add a note to the README. My suggestion it to simply do all the colorscheme stuff after setting options in your vimrc.

Reference: altercation/solarized#102

@tomvanderlee
Copy link
Author

That fixed it!

Thanks for helping me and thanks for creating this awesome colorscheme!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants