Saturday, July 9, 2011

Re: Custom Syntax

On 09/07/11 18:47, Nicholas Cole wrote:
> Dear List,
>
> I want to add some definitions to one of the standard syntax files.
> What is the best way to do this. Obviously, I could copy the whole
> file and make my changes on a local user copy, but is there a way to
> read in the default file first and then add some definiations? I've
> tried searching for this sort of thing, but it looks as if most people
> start syntax files from scratch.
>
> Best wishes,
>
> Nicholas
>

Well, you could add additional rules in (on Unix)
~/.vim/after/syntax/whatever.vim, or (on Windows)
~/vimfiles/after/syntax/whatever.vim (replacing "whatever", above and
below, by the syntax name) and they would be sourced after
$VIMRUNTIME/syntax/whatever.vim, but the problem is that they would not
nec"essarily override the defaults: e.g. a ":syn keyword" in the default
file will not be overridden by a ":syn match" in an after-script...

So the recommended way to go is to copy the script in an "early"
directory (e.g. on Linux, as ~/.vim/syntax/whatever.vim) and make the
changes in that copy. The statements

if exists("b:current_syntax")
finish
endif

near the beginning of the standard script (keept it in yours), and

let b:current_syntax = "whatever"

near the end of yours (copied from the standard one), will ensure that
the "standard" script will become a do-nothing script.


Best regards,
Tony.
--
Show me a man who is a good loser and I'll show you a man who is
playing golf with his boss.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: