Best regards,
Kristoffer
Hello Kristoffer,
like this in your .vimrc
colorscheme=mycolors2
autocmd FileType python colorscheme=mycolors1
Hth Michael
--
Life is Xerox, and you're just a copy
I believe the current colorscheme is a vim-wide setting, so if
you've got a mix of python and non-python buffers open, you may
have to toggle the colorscheme on the BufEnter event. Something like
au BufEnter * exec 'colorscheme '.(&ft=='python' ? 'elflord' :
'peachpuff')
(okay...randomly chosen colorschemes, not asthetically chosen)
should allow you to toggle the colorscheme depending on the
buffer you're currently editing. Man, does that autocmd give me
a headache :)
-tim
Thank you very much! It was almost correct. ;o)
Just for reference, the correct .vimrc lines should be
colorscheme mycolors2
autocmd FileType python colorscheme mycolors1
That is, without the equal signs ( = ).
Best regards,
Kristoffer
2008/8/6 Michael Wagner <michae...@web.de>:
/Kristoffer
2008/8/6 Tim Chase <v...@tim.thechases.com>:
Highlight groups, and therefore color schemes, apply to all files in all
windows of all tabs of one instance of Vim. If you have an HTML file in
one window, its CSS style sheet in another, and a page of Vim help in a
third, you cannot apply three different colorschemes to them. Similarly
for a Python script, a Vim script and a Vim helpfile being displayed
side-by-side.
However, each syntax script defines highlight groups groups with names
starting with the syntax name, then links as many as possible to
existing highlight groups.
To highlight python scripts otherwise than all others, you would thus
have to write your own colorscheme, because by default, colorschemes
accept the default links set by the syntax scripts: a colorscheme
defines Comment, then syntax/c.vim links cComment to it,
syntax/python.vim links pythonComment to it, syntax/vim.vim links
vimComment, and so on, all that with ":hi link default" statements,
which are applied only if the same group is not defined elsewhere. In
order to highlight python files differently than all others, you would
have to explicitly define pythonComment, pythonStatement, etc., maybe
define a new pythonLiteral group (or something) to which you would link
pythonString, pythonNumber, pythonRawString, etc. Check
$VIMRUNTIME/syntax/python.vim for the names which are atually used.
Best regards,
Tony.
--
Rudin's Law:
If there is a wrong way to do something, most people will do it
every time.
I'm not sure I understand your point here. Tim's hack worked
perfectly: Opening, say, my .vimrc, an HTML document and a Python
script in three buffers applies my default colorscheme to the first
two files and a different colorscheme to the Python script. Vim also
remembers the different colorschemes when I change buffers.
If I understand your mail correctly, you say that Vim can't work this way?
If you use Vim with 1 window, editing 1 buffer at a time, then this
will certainly work fine.
If you use Vim with multiple split windows, possibly in multiple tabs,
this will not work.
Just try :help in one of your python buffers, and you will see that
the two windows use the same colorscheme.
Ah, ok, didn't think about that. Well, I wanted this hack just to
avoid setting the colorscheme manually every time I open a python
script. It doesn't really matter if it is being inherited by other
split windows. :o)
You may be mixing the ideas of color schemes with
syntax-highlighting files. Syntax files usually identify blocks
of text as certain types (such as "identifier", "string",
"constant", "preprocessor command", etc). The colorschemes then
take these common types and map them to a color.
It's certainly possible to have CSS and JavaScript included in
the HTML, as shown in your $VIMRUNTIME/syntax/html.vim script.
It should properly map these to the types which your colorscheme
should then map to your colors of choice. As an example, the
following, saved as an HTML file:
--------------------
<html>
<head>
<title>Foo</title>
<script><!--
var i = 42;
alert("Hello world");
//--></script>
<style>
a {color:red;}
h1 {color:green;}
</style>
</head>
<body>
<h1>Works for me®</h1>
</body>
</html>
--------------------
highlights the HTML with HTML syntax, the JavaScript as JS
syntax, and the CSS as CSS syntax -- all the way one would expect.
If not, you may be running an older version, or you might have
some setting that has disallowed Vim from behaving the way you
desire.
-tim
You wouldn't need to touch the syntax files. What you would need is a
colorscheme (probably own-coded) which defines non-default highlights
for at least one set of the css* and html* highlights. Of course,
embedded CSS (as e.g. in a <style> tag in the <head> part of your HTML
page) would be highlighted as CSS.
Best regards,
Tony.
--
Dimensions will always be expressed in the least usable term.
Velocity, for example, will be expressed in furlongs per fortnight.
However, your question seems to confuse colorschemes with
syntax-highlighting. You *can* have your css sections highlighted
differently. See how syntax/vim.vim handles including perl highlighting
inside vim script files:
if (g:vimsyn_embed =~ 'p' && has("perl")) &&
filereadable(expand("<sfile>:p:h")."/perl.vim")
unlet! b:current_syntax
syn include @vimPerlScript <sfile>:p:h/perl.vim
if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'p'
syn region vimPerlRegion fold matchgroup=vimScriptDelim
start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
syn region vimPerlRegion fold matchgroup=vimScriptDelim
start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
else
syn region vimPerlRegion matchgroup=vimScriptDelim
start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
syn region vimPerlRegion matchgroup=vimScriptDelim
start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
endif
else
syn region vimEmbedError start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+
syn region vimEmbedError start=+pe\%[rl]\s*<<\s*$+ end=+\.$+
endif
Well, that's complicated some by making the inclusion optional (ie.
g:vimsyn_embed) and by optional folding (g:vimsyn_folding).
The important part is: (assuming no folding)
syn include @vimPerlScript <sfile>:p:h/perl.vim
syn region vimPerlRegion matchgroup=vimScriptDelim
start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
There's start and end triggers so vim can recognize where the different
syntax highlighting is to begin and end. The "syn include" sets up a
highlighting group (vimPerlScript) that will be highlighted with
syntax/perl.vim.
Regards,
Chip Campbell