Vim 折叠以 { 结尾的每一行,但不折叠类 [英] Vim folding every line ending in { but not classes

查看:59
本文介绍了Vim 折叠以 { 结尾的每一行,但不折叠类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算折叠所有以 { 结尾的行,但不折叠类.到目前为止,我想出了这个命令:

I intend to fold all the lines ending in { but not classes. So far I have came up with this command :

:%g/.\{-}\(class\)\@!.*{$/normal! zf%

但这也会匹配包含 class 的行.

But this would match also the lines containing class.

推荐答案

有几个问题:

  1. 来自:help/\@!:您不能使用\@!"在匹配位置之前查找不匹配的位置".使用 \@<!,在其中包含可能的字符,并删除无用的(因为它没有锚定)非贪婪的第一个匹配.
  2. :global 命令将光标置于匹配行的第一列,因此添加一个 $ 使 % 一直工作.
  3. 后续的内折必须在外折打开的情况下定义:zv.
  1. From :help /\@!: "You can't use "\@!" to look for a non-match before the matching position". Use \@<!, include the possible characters in between in there, and drop the useless (because it's not anchored) non-greedy first match.
  2. The :global command places the cursor on the first column of matching lines, so add a $ to make the % work all the time.
  3. Subsequent inner folds must be defined with the outer fold open: zv.

因此:

:%g/\%(class.*\)\@<!{$/normal! $zvzf%

这篇关于Vim 折叠以 { 结尾的每一行,但不折叠类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆