Looking to define a match group for modelines. vim defines two patterns for modelines:
The first form:
[text{white}]{vi:|vim:|ex:}[white]{options}
[text{white}]
empty or any text followed by at least one blank character (<Space>
or<Tab>
);ex:
always requires at least one blank character{vi:|vim:|ex:}
the stringvi:
,vim:
orex:
[white]
optional white space{options}
a list of option settings, separated with white space or:
, where each part between:
is the argument for a:set
command (can be empty)
Examples:
vi:noai:sw=3 ts=6 ~
vim: tw=77 ~
The second form (this is compatible with some versions of Vi):
[text{white}]{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text]
[text{white}]
empty or any text followed by at least one blank character (<Space>
or<Tab>
);ex:
always requires at least one blank character{vi:|vim:|Vim:|ex:}
the stringvi:
,vim:
,Vim:
orex:
[white]
optional white spacese[t]
the stringset
orse
(note the space); WhenVim
is used it must beset
.{options}
a list of options, separated with white space, which is the argument for a:set
command:
a colon[text]
any text or empty
Examples:
/* vim: set ai tw=75: */ ~
/* Vim: set ai tw=75: */ ~
I currently have a simple pattern to match the modelines I've written:
syntax match Modeline ".*\s+vim:\sset.*:.*"
but I would like to create a match group that matches on all lines Vim treats as modelines (the pattern above misses some of the nuance with ex for example). I imagine vim internally has regex expressions that match these patterns. I'd like to use those expressions in a match group.
:help modeline
) could easily be turned into a regular expression. I doubt there's a way to access Vim's internal modeline matching mechanism. I don't know but these things are typically not exposed. I'd write a regex that matches modelines as they are documented.