开发者

Is it possible to have a Vim syntax file command span multiple lines?

I'm trying to create a syntax file and I want to create some keyword groups for different colour highlighting (e.g. reserved words, operators etc. would be different colours). I can get this to work by doing one of the following two options:

Option 1

syn keyword MyLangOperators operator1 operator2 operator3
syn keyword MyLangOperators operator4 operator5 operator6

syn keyword MyLangReserved reserved1 reserved2 reserved3
syn keyword MyLangReserved reserved4 reserved5 reserved6

This isn't too bad, but if I'm trying to keep them in alphabetical order, it gets really messy once the number of reserved/operators etc. gets up there. Especially if you need to add new ones in the middle somewhere.

Option 2

syn keyword MyLangOperators operator1
syn keyword MyLangOperators operator2
syn keyword MyLangOperators operator3
syn keyword MyLangOperators operator4
syn keyword MyLangOperators operator5
syn keyword MyLangOperators operator6

syn keyword MyLangReserved reserved1
syn keyword MyLangReserved reserved2
syn keyword MyLangReserved reserved3
syn keyword MyLangReserved reserved4
syn keyword MyLangReserved reserved5
syn keyword MyLangReserved reserved6

This options is much easier to add res开发者_如何学Pythonerved/operators later on because it is easy to keep them in alphabetical order. However, there is a lot of repeated text for every line (i.e. syn keyword [groupname]).

Is there any possible way to be able to span the command over multiple lines? Something like this maybe:

syn keyword MyLangOperators ~
    operator1 ~
    operator2 ~
    operator3 ~
    operator4 ~
    operator5 ~
    operator6

syn keyword MyLangReserved ~
    reserved1 ~
    reserved2 ~
    reserved3 ~
    reserved4 ~
    reserved5 ~
    reserved6

In this case the tilde (~) would be a signal to the Vim editor that the command continues onto the next line.

Is there anything like this or am I stuck with option 1 or 2 (most likely I'd go with 2)?


this will do it (:help line-continuation)

syn keyword MyLangOperators
    \ operator1
    \ operator2
    \ operator3
    \ operator4
    \ operator5
    \ operator6
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜