我想使用基于Vim语法的折叠来折叠
python代码中的函数定义.所以我在我的.vim / Syntax / python.vim中添加了以下内容:
setlocal foldmethod=Syntax syn sync fromstart syn region pythonFunctionFostart="^\z(\s*\)\%(def\|class\) " skip="^\s*$" end="^\ze\%(\z1\s\)\@!." fold transparent
这有效;它还吞噬了函数之间的空行(不像foldmethod = indent),这是我想要的.但是,我不希望折叠“def function():”行.据我所知,文档可以做到以下几点:
syn region pythonFunctionFold start="^\z(\s*\)\%(def\|class\) .*\n\zs." skip="^\s*$" end="^\ze\%(\z1\s\)\@!." fold transparent
但这会导致vim根本不创建任何折叠. (我当然尝试使用普通搜索启动正则表达式,但它确实有效).两者都不起作用:
syn region pythonFunctionFold start="^\z(\s*\)\%(def\|class\) .*\n."ms=e skip="^\s*$" end="^\ze\%(\z1\s\)\@!." fold transparent
也不是hs = e,rs = e
我尝试的一切都包括def,或根本不起作用. (我想vim不喜欢我的语法regexp中的换行符).是否有一些简单的方法可以在regexp匹配后使语法折叠开始行?
编辑:我也尝试了以下内容:
syn match pythonFunctionFold "^\(\s*\)\%(def\|class\) .*\n\zs\(\s*\n\|\1\s\+.*\n\)\+" fold transparent
当我搜索模式(使用/)时,它与我想要折叠的区域完全匹配,而“:help Syntax”声称支持多行匹配.但我仍然没有折叠.
解决方法
我担心这可能是不可能的.从Syntax.txt,在:syn-multi-line下:
When using a start pattern with an offset,the start of the match is not allowed to start in a following line. The highlighting can start in a following line though. Using the “\zs” item also requires that the start of the match doesn’t move to another line.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。