-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Vim colorscheme leaves a wake of destruction when switching away #102
Comments
I'll look into it as well. The only autocommand I use on colorscheme |
I don't think it's the autocommand. I think it has to do with the fact |
What's a better test for this? Unless I'm wrong vimCommand just isn't |
From
That means "unless At least, that's my best understanding of it. Clearly it's an incomplete explanation as other groups appear fine. |
Not really a Solarized issue then, no? I could make a universal syntax loader in an ftdetect or just a BufNewFile/BufRead to preempt syntax detection and try to reset the syntax easily enough. |
Well, it's only a Solarized issue in that Solarized is doing something Vim doesn't seem to support. The ability to override highlight group linkings was intended to be user specific rather than colorscheme specific. So, it's not surprising that there's some friction here. I do have hope, though, as |
Tim, can you point me to the docs on this being bad form in a colorscheme? I buy what your saying but just didn't run across it, or didn't pay enough attention when I did. I'm sure there is other stuff I've been out of bounds on as well and really would like to ensure that this is a good example of form, not just function, by complying with guidelines as I can. I see a couple options:
Thoughts? Other directions? |
The Vim help isn't too explicit about this, but if you read Switching away from linking isn't going to solve it. In fact I don't think a full clear is going to cut it, as that already happens when switching colorschemes. Vim provides The only other solution I can think of right now is to separate out the basic color definitions from all the filetype specific stuff, so that people that want to switch colorschemes can opt out of the latter. I hope to top that. |
Tim, I don't know if this is the right approach, but if I run the following starting in solarized (in a new buffer for simplicity):
(returns)
I think we can actually reset more or less fully by setting the filetype again (in the same buffer):
Which results in:
I could automate this into an autocmd. I might be missing something here, so don't let me head off into the bush on this. |
I have this provisionally, seems to do the trick:
|
Bizarrely, this seems to work the first time, but if I cycle colorschemes again, it seems to break. |
Dammit, you're right. |
I was actually going to open a ticket on this earlier. For the longest time I was attempting to test solarized and assumed it was just broken. Reason was as @tpope said I was attempting to load it by |
@lusis, calling |
I was originally using a twilight colorscheme port. When ever I cycled to solarized, the only thing I got was a single font color and the background color change. When I forced solarized for a given filetype, it worked great until I started cycling colorschemes again. I don't do it that often but I do use different colorschemes for python vs ruby so occasionally gvim cycles on me automatically when I switch language contexts. I can probably duplicate it again fairly easily. |
@lusis, if you are changing colorschemes on a per filetype basis, I can tell you you're definitely twisting Vim in ways it was never meant to be twisted (and thus it's not really surprising that things might break, even if the particular reason isn't immediately obvious). What happens if you have a window split with a Python and Ruby file open at the same time? |
@tpope I totally agree. The only time it bites me in the ass is when I open a JSON file while working on Ruby. I never find myself working on Python and Ruby in the same "session". It's mainly there to help with the mental context switching when I swap projects. As to the original issue I saw, I wasn't actually doing any filetype switching. I was loading vim with my original colorscheme. I typed |
I've narrowed it down to something that has to do with for reference, I'm using my fork of vim-javascript but it also applies to the origin as well
That's as far as I've gotten. Not a good solution since you'll have to change it back to |
That's definitely good intel and a solid repro case. Thanks. |
Hi all, Sorry to barge in here a year after the last comment and suggest to close an issue on a project I'm not involved in (although I am a happy user :-) however I believe that: 1. this is caused by a bug in Vim and 2. I've found a fairly elegant workaround. So I suppose this issue can be closed? Several years ago I wrote a color scheme switcher plug-in for Vim but never published it. Shortly after creating my plug-in I noticed the behavior described in this issue and became annoyed by it, convinced that it was a bug in Vim. I even went so far as to try and fix the issue inside the Vim C code but that was a bit too much for me :-]. Back then I had never heard of Solarized; I encountered the problem with a couple of other color schemes (including my own). Today I decided to publish the color scheme switcher plug-in (see xolox/vim-colorscheme-switcher) and before I published the plug-in I decided to take another stab at fixing the problem described here. I tried all sorts of nasty hacks but ended up with a fairly elegant workaround that doesn't seem too fragile. The readme / homepage contains an explanation of how it works (I'm quoting it below for your convenience). The way Vim color schemes are written isn’t really compatible with the idea of quickly switching between lots of color schemes. In my opinion this is an ugly implementation detail of how Vim works internally, in other words I think it’s a bug that should be fixed… Here are some references that explain the problem in some detail:
Since this behavior hinders cycling through color schemes, the color scheme switcher plug-in includes a workaround that should hide the problem:
Probably this solution is still not perfect, but it’s a lot better than the behavior out of the box: Before I implemented the steps above, when I would cycle through my color schemes, Vim would eventually end up with black text on a white background and nothing else! With the steps above, I can cycle as many times as I want and all of the color schemes I’ve checked so far look fine. I would love feedback on the (technique used by the) color scheme switcher; I hope it works as well for you as it does for me. I tested it in Vim 7.3 on Linux (GTK) and in MacVim 7.3. |
Sorry for resurrecting this thread, but this "bug" is still a problem in Vim 8. As xolox details in the post above this one, he found a workaround that fixes the issue. However, he only implemented this fix within his plugin, and the plugin doesn't allow for switching to a specific colorscheme by name. I took the liberty of extracting the relevant functions and making a custom If anyone stumbles across this problem in the future and is looking for a quick fix, simply add this to your vimrc, use
|
Thanks for posting this. I was having similar issues with the Afterglow color scheme. Cheers |
FYI, to avoid this issue my Solarized 8 fork does not define filetype-specific highlight groups by default. A setting is available if you still want to do so. |
@lifepillar Why not include @auwsmit's solution as an option? Speaking of: @auwsmit, may I include your answer in a related plugin? Care to release it under a license, so I can do so? (= |
I don't mind at all, but that code almost entirely came from xolox's vim-colorscheme-switcher which is licensed under MIT, so I guess ask him, or include the MIT license with his copyright in your plugin to be safe. I'm not super familiar with license/copyright conventions. |
@ELLIOTTCABLE I don't want to add bloat to the colorscheme. IMO, this issue can only be properly addressed in Vim core. |
Easiest way to demonstrate:
Note that the highlighting for
vimCommand
and other highlight groups is gone.I haven't figured out the precise trigger yet (I'll probably take a closer look this weekend), but I can tell you that it never seems to happen if you
:hi link
rather than directly override a group's colors.The text was updated successfully, but these errors were encountered: