我正在玩 vim-ruby 缩进,那里有一些非常复杂的正则表达式:
" Regex used for words that, at the start of a line, add a level of indent.
let s:ruby_indent_keywords = '^\s*\zs\<\%(module\|class\|def\|if\|for' .
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' .
\ '\|rescue\):\@!\>' .
\ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
在 vim 文档的帮助下,我将其解读为:
start-of-line <any number of spaces> <start matching> <beginning of a word> /atom
<one of provided keywords> <colon character> <nothing> <end of word> ...
我有些疑惑:
- 它真的匹配':'吗?似乎不像那样工作,但我看不到冒号是正则表达式中的一些特殊字符。
- 为什么有
\zs
(比赛开始)而没有\ze
(比赛结束)? - \%() 是做什么的?它只是某种形式的分组吗?