匹配vim语法文件中的选项卡

时间:2011-12-23 06:02:56

标签: regex vim syntax

我正在使用Vim为我的待办事项编写语法文件 实际上,当他们以w:,h:或p:开头时,我会突出显示这些行:

syn match todoHome  "^h: "
syn match todoWork  "^w: "
syn match todoPersonal  "^p: "
syn region todoHome start=/^h: / end=/\n/
syn region todoWork start=/^w: / end=/\n/
syn region todoPersonal start=/^p: / end=/\n/
syn region todoDone start=/^x: / end=/\n/

我想用标签创建一些子任务并以相同的方式突出显示它... 我知道正则表达式可以做到这一点,我试过:

syn region todoWork start=/^|[\t ]+w: / end=/\n/

但它不起作用......有任何线索吗?

1 个答案:

答案 0 :(得分:2)

| => \|

:help pattern

1. A pattern is one or more branches, separated by "\|".  It matches anything
   that matches one of the branches.  Example: "foo\|beep" matches "foo" and
   matches "beep".  If more than one branch matches, the first one is used.

   pattern ::=      branch
        or  branch \| branch
        or  branch \| branch \| branch
        etc.

+ => \+

\+  1 or more   as many as possible (*)

或在模式的开头添加\v

Use of "\v" means that in the pattern after it all ASCII characters except
'0'-'9', 'a'-'z', 'A'-'Z' and '_' have a special meaning.  "very magic"