如何折叠 vim 中所有出现的正则表达式?
我的一位同事正在使用一个可怕的源代码编辑器,它会在代码中留下奇怪的注释。在 Visual Studio 中,我创建了一个宏 ,这只是折叠所有这些评论块,这样我就不必看到它们。
现在我想在 vim 中做同样的事情。
这个正则表达式匹配这些块中的每一个:
/^.*\/\* EasyCODE.*\(\(\n.*\*\/\)\|\(\n.*\/\*.*\)\|\(\n\/\/.*\)\)*/
现在我打赌有一种非常好的方法可以在 vim 中折叠该模式的所有匹配项。然而,我对 vim 还很陌生,不知道该怎么做。
你能在那里帮我吗?
编辑:一些示例:
这些注释块始终以 /* EasyCODE
开头。有时注释在第一行末尾有一个结束 */
,有时仅在下一行。以下行可能包含也可能不包含其他“/* EasyCODE
...”块。
这些块之一可能看起来像这样
/* EasyCODE ) */
/* EasyCODE ( 0
some text */
/* EasyCODE F */
或像这样
/* EasyCODE V8 */
/* EasyCODE ( 0 */
或像这样
/* EasyCODE > */
正如我所说,上面的正则表达式捕获了所有这些块。
A colleague of mine is using a horrible source code editor that leaves strange comments all over the code. In Visual Studio, I created a macro, that simply folds all those comment blocks so I don't have to see them.
Now I would like to do the very same thing in vim.
This regex matches every one of those blocks:
/^.*\/\* EasyCODE.*\(\(\n.*\*\/\)\|\(\n.*\/\*.*\)\|\(\n\/\/.*\)\)*/
Now I bet there is a really nice way to fold all matches of this pattern in vim. However, I am rather new to vim and don't know how to do this.
Could you help me there?
Edit: some examples:
These comment blocks always begin with /* EasyCODE
. Sometimes the comment have a closing */
right on the end of the first line, sometimes only on the next line. The following lines might or might not contain additional "/* EasyCODE
..." blocks.
One of these blocks could look like this
/* EasyCODE ) */
/* EasyCODE ( 0
some text */
/* EasyCODE F */
or like this
/* EasyCODE V8 */
/* EasyCODE ( 0 */
or like this
/* EasyCODE > */
As I said, the above regex catches them all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全清楚你的块的细节(因此关于提供示例的评论),但你可以使用这样的东西:
这将配置“标记”折叠方法,该方法在代码中查找某些标记,然后它会将起始标记设置为
/* EasyCODE
并将结束标记设置为*/
。希望这会给您一些帮助您入门。如果您可以发布示例源文件,我也许可以提供更多建议。I'm not completely clear on the details of your blocks (hence the comment about providing an example), but you could use something like this:
This will configure the 'marker' fold method that looks for certain markers in the code and then it will set the starting marker to
/* EasyCODE
and the ending marker to*/
. Hopefully this will give you something to get you started. If you could post a sample source file, I may be able to offer some more advice.