我在玩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 (比赛结束)?发布于 2012-05-16 12:32:53
:\@!说,只有在没有冒号的情况下,如果我正确阅读,才能匹配。我不熟悉与之匹配的ruby语法,因此这可能不太正确。有关lookarounds.:help /\@!和周围的主题,它可以有一个没有\ze的\zs,这只是意味着匹配的结束在正则表达式的末尾。相反,true.\%(\)只创建一个分组,就像\(\)一样,只是这个组不能作为反向引用使用(就像在:substitute命令中一样)。发布于 2012-05-16 12:34:32
/搜索。使用:set incsearch可以帮助您在键入正则表达式时查看匹配的内容。\zs和\ze不影响匹配内容,而是确定匹配文本的哪一部分用于:s/substitute()等函数。您可以通过使用/和'incsearch'选项集执行搜索来检查--您可以开始搜索文本中的字符串,该字符串将被高亮显示,然后添加\zs和\ze将更改匹配文本的突出显示。没有必要“关闭”\zs和\ze,因为人们只能放弃比赛的开始或结束。\1、\2或submatch()一起使用,如:h \%()中所述:allows using more groups and it's a little bit faster. \%(\) A pattern enclosed by escaped parentheses. Just like \(\), but without counting it as a sub-expression. This
https://stackoverflow.com/questions/10617814
复制相似问题