Original title was «Language-specific color-schemes prevent simpler ones from coloring certain language-specific tags»
I'm using gVim 7.3 (on Ubuntu 12.04 Arch x86/64, for that matters).
I think I can finally express exactly what I mean (I still couldn't find the correct command, assuming it even exists!). Basically this is the flow:
The result is that the session is cluttered with "homeless" group that obscure the basic ones and prevent some words to be highlighted at all. These homeless groups look like the following:
INPUT :hi vimCommand
Enter
OUTPUT vimCommand xxx cleared
By the way something similar is experienced and issued in the Solarized's github issue tracker → Vim colorscheme leaves a wake of destruction when switching away
Probably, a good solution would be clearing the current session's "highlight" variables (I'm not talking about variables like smartindent
, encoding
, number
, but rather about variables like Statement
, Comment
rubyClass
, xmlTag
, i.e. the ones defined by commands like hi link ...
, highlight ...
, etc.).
If anyone could explain how it is stored in memory, it could maybe help me figuring out how to clean it away (I've tried saving a session through :mksession mysession.vim
and then looking into it, but there's no trace of any syntax highlighting variable).
Also, and this is just a vague supposition, it seems that the reason why :hi clear
doesn't clean up the highlight groups is that the "leftovers" were defined through an indirect definition (e.g. hi link
).
When my default colorscheme (a modified version of blueshift) is loaded every tag that should be highlighted is correctly coloured.
During the session, I switch to jellybeans colorscheme (:colo jellybeans
), which has many more options than my default color-scheme:
If I switch again to my default colorscheme (:colo blueshifted
), some highlighting is disabled:
It seems that at the beginning of the session if I use a color-scheme that doesn't specify the behaviour for some language-specific tags, those tags are auto-coloured using some existing colors.
I know that jellybeans's language-specific tags remain in the "cache" and are the responsible for disabling the auto-coloring feature, because if I switch between colorschemes that don't have language-specific tags (without ever using jellybeans), the auto-coloring isn't ruined.
The same happens with other color-schemes (for example railscasts.vim uses HTML-specific coloring). I know I can solve the issue by adding the missing tags in the less-specific color-scheme, but I'm looking for a more general solution.
The Questions
what can I do to avoid that these auto-setting colors (used when the first color-scheme is loaded) are disabled when a less detailed color-scheme is loaded after a more-detailed color-scheme?
Can I clean up the session cache (i.e. remove the specific tags used by jellybeans.vim from the "session cache") when I change color-scheme?
My attempts These are the commands I used in various combination, to no avail:
:syntax off
:syntax clear
:hi clear
:syntax reset
The only thing that works (obviously!) is redefining by hand the hi link
commands missing in the "simple" colorscheme. But of course this is no different by using the other colorscheme (like Solarized) with changed colors. Of course this is not a solution to the question "How do you remove highlighting groups leftovers?".
Show activity on this post. Thus, after your search, just hit return again in command mode, and the highlighting disappears.
You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.
Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn't parse the whole file (to keep it fast), so the highlighting has its limitations.
I may be a bit late :-) but I believe I solved this problem. Below is a quote of the post I made on the Solarized issue tracker on GitHub.
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:
xolox#colorscheme_switcher#find_links()
.xolox#colorscheme_switcher#restore_links()
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With