On 07/06/09 19:26, Jeri Raye wrote:
>
> Hi
>
> I have my default color file in the directory:
> C:\Program Files\Vim\vimfiles\colors
>
> What do I need to do to let vim load a different color scheme when a
> certain file type is detected?
>
> For example:
> If I creat a colorscheme file aaa.vim
> Where does this file needs to be stored?
> And how do I let vim load this when a filetype of aaa is detected?
>
> In other words:
> if I open "myfile.aaa" in gvim I want the color scheme aaa.vim
>
> Rgds,
> Jeri

You could do it by having the line

        colorscheme aaa

(by the colorscheme name) in a file named (on Windows) 
~/vimfiles/after/ftplugin/aaa.vim or (on Unix etc.) 
~/.vim/after/ftplugin/aaa.vim (aaa after /ftplugin/ being the filetype 
name). Note that the filetype name is NOT necessarily the same as the 
file's extension: for instance, files named *.htm get the filetype 
"html" by default; files *.h can get either of the filetypes "c" or 
"cpp"; etc.

However, there is a problem with this approach: colorschemes are 
"global" (they affect all Vim) while filetypes are "buffer-local" (they 
affect only the file in question). So, whenever you edit several files 
in parallel, the whole of Vim would get the colorscheme corresponding to 
the filetype loaded last. There is no way to set different colorschemes 
in different windows _in parallel_, unless you write a new colorscheme 
(I'm pretty certain that this kind of colorscheme doesn't yet exist) 
with different colors for the syntax highlights usually linked from 
different syntax scripts to the standard names. For instance, different 
":hi" commands for cComment, htmlComment, vimComment, helpComment, etc., 
and similarly for the various kinds of identifier, of statement, etc., 
depending on the language. You would still be unable to set different 
colors at the same time for "global" highlights such as Normal, 
StatusLineNC, Search, Cursor, etc.


Alternately, if you are willing to have non-current split-windows 
coloured according to the filetype of the current window, you could 
arrange to set the colorscheme in a BufWinEnter autocommand, maybe as 
follows (untested, and applies [I think] to Unix/Linux/Cygwin/MacOsX or 
to Windows, but not Mac OSes previous to Mac OS X):

augroup filetype_colorscheme
        au BufWinEnter *
        \ if !exists('b:colors_name')
            \ | if filereadable($HOME . '/' .
                    \ (has('unix')? '.vim' : 'vimfiles')
                    \ . '/colors/' . &ft . '.vim')
                \ | let b:colors_name = &ft
            \ | else
                \ | let b:colors_name = default
            \ | endif
        \ | endif
        \ | exe 'colorscheme' b:colors_name
augroup END

I'm intentionally using a descriptive autocommand group to make it 
easier to unset this autocommand or to replace it by something else.


Best regards,
Tony.
-- 
Gordon's first law:
        If a research project is not worth doing, it is not worth doing
well.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to