加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Vim:在正则表达式匹配后如何在线上开始语法折叠? (python函数)

发布时间:2020-12-16 01:57:11 所属栏目:安全 来源:网络整理
导读:我想使用基于Vim语法的折叠来折叠 python代码中的函数定义.所以我在我的.vim / syntax / python.vim中添加了以下内容: setlocal foldmethod=syntaxsyn sync fromstartsyn region pythonFunctionFostart="^z(s*)%(def|class) " skip="^s*$" end="^ze
我想使用基于Vim语法的折叠来折叠 python代码中的函数定义.所以我在我的.vim / syntax / python.vim中添加了以下内容:

setlocal foldmethod=syntax
syn sync fromstart
syn region  pythonFunctionFostart="^z(s*)%(def|class) " skip="^s*$" end="^ze%(z1s)@!." fold transparent

这有效;它还吞噬了函数之间的空行(不像foldmethod = indent),这是我想要的.但是,我不希望折叠“def function():”行.据我所知,文档可以做到以下几点:

syn region  pythonFunctionFold  start="^z(s*)%(def|class) .*nzs." skip="^s*$" end="^ze%(z1s)@!." fold transparent

但这会导致vim根本不创建任何折叠. (我当然尝试使用普通搜索启动正则表达式,但它确实有效).两者都不起作用:

syn region  pythonFunctionFold  start="^z(s*)%(def|class) .*n."ms=e skip="^s*$" end="^ze%(z1s)@!." fold transparent

也不是hs = e,rs = e

我尝试的一切都包括def,或根本不起作用. (我想vim不喜欢我的语法regexp中的换行符).是否有一些简单的方法可以在regexp匹配后使语法折叠开始行?

编辑:我也尝试了以下内容:

syn match pythonFunctionFold "^(s*)%(def|class) .*nzs(s*n|1s+.*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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读