Kamil Kisiel wrote:
On 9/21/06, A.J.Mechelynck <[EMAIL PROTECTED]> wrote:
Kamil Kisiel wrote:
> I would like to define keywords for syntax highlighting that are
> specific to a particular project. For example, when using some
> third-party API there are often frequently used keywords that I'd like
> to highlight when using that API. What's the best way to set this up
> with Vim, and to have the settings load automatically whenever I edit
> files from that project?
>

Since you are specifying practically nothing, I shall assume that the
files in question are of filetype foo, of filename *.foo, and that the
files "from that project" are distinguished by being anywhere in
directory ~/bar or its subdirectories to any depth.

I suggest the following (untested):

create ~/.vim/after/syntax/foo.vim (on Unix) or
~/vimfiles/after/syntax/foo.vim (on Windows) (and create any needed
directories), as follows (or similar):

" supplementary syntax for foo-type files of project bar
if expand('%:p') !~ '^' . fnamemodify(expand('~/bar'),':p')
     " current file is not of this project --
     " nothing to do
     finish
endif
" define additional keywords
sy keyword MyKeywords blah blahblah foobarbaz
" use «:hi default» to avoid conflict with a possible colorscheme
" which we might write at any future time
hi default MyKeywords ctermbg=cyan ctermfg=white guibg=#99FFFF




Best regards,
Tony.


Right, I intentionally left the question a bit vague to get the "foo"
type response so that nothing filetype specific worked its way in :)
And yes, by project I meant just a directory containing the source
files.

Is there some way the settings could be incorporated in to an
automatically loaded file associated with the project? I'm thinking if
there's some kind of hook for the :cd command, one could do something
like place a "project.vim" file in to the directory and then have vim
source it upon changing to that directory.

Well, yes, that is possible if you set the proper autocommands for it; but beware that changing the colorscheme or using "syntax on" to reset your highlight colours might play havoc with whatever syntax colouring settings would be set by such a "project.vim" script.

You may want to store project-specific scripts for various autocommand events (e.g. BufRead/BufNewFile; FileType; Syntax) in a project directory but how would you access them if you have comon settings for a whole tree? In any case you should write the appropriate autocommands to source them when the event is triggered, e.g. in your vimrc or in a "custom" global plugin. You should also make sure that the default scripts and your additions are sourced in the right sequence.

e.g. (untested)

        au Syntax *
        \   let s:scriptname =
        \       fnamemodify(expand("<afile>"),":p:h")
        \       . "syntax_" . expand("<amatch>") . ".vim"
        \ | if filereadable(s:scriptname)
        \ |   source s:scriptname
        \ | endif
        

Note: When replying to a list post, "Reply to all" is better than "Reply to sender" because it allows all list subscribers to see your reply and react to it.


Best regards,
Tony.

Reply via email to