Vim folding every line ending in { but not classes

扶醉桌前 提交于 2019-12-24 08:51:16

问题


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%

But this would match also the lines containing class.


回答1:


There are several problems:

  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.

Ergo:

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


来源:https://stackoverflow.com/questions/20141984/vim-folding-every-line-ending-in-but-not-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!