How to collapse all occurrences of a regex in vim?

My colleague uses a terrible source code editor that leaves strange comments throughout the code. In Visual Studio, I created a macro that simply stacks all these comment blocks, so I don't need to see them.

Now I would like to do the same in vim.

This regular expression matches each of these blocks:

/^.*\/\* EasyCODE.*\(\(\n.*\*\/\)\|\(\n.*\/\*.*\)\|\(\n\/\/.*\)\)*/

Now I'm sure there is a really good way to reset all matches of this pattern in vim. However, I'm pretty new to vim and don't know how to do this.

could you help me?

Edit: a few examples:

These comment blocks always begin with /* EasyCODE. Sometimes a comment has a closure */on the right at the end of the first line, sometimes only on the next line. The following lines may or may not contain additional " /* EasyCODE..." blocks .

One of these blocks might look like this:

/* EasyCODE ) */
/* EasyCODE ( 0 
some text */
/* EasyCODE F */

or how is it

/* EasyCODE V8 */
/* EasyCODE ( 0 */

or how is it

/* EasyCODE > */

As I said, the above regular expression catches them all.

+3
source share
1 answer

I don’t quite understand the details of your blocks (hence the comment about providing an example), but you can use something like this:

:set foldmarker=/\*\ EasyCODE,\*/
:set foldmethod=marker

"", , /* EasyCODE, - */. , -, . , .

:help folding
:help 'foldmarker'
:help 'foldmethod'
:help fold-marker
+2

Source: https://habr.com/ru/post/1765781/


All Articles