in reply to Perl equivalent of C-style

I'm not a VI or Perl expert, but I seem to remember someone saying you could embed Perl in VI. If so, I'm guessing you could attach Perl scripts to a custom command. If that's the case, create two commands. Attach one to a script that adds block comments and the other to a script that removes them. Define your C-style comment delimiters (not /* */, since they tend to come up often in regex), then run the block comment script on the current file.

The script runs through your file looking for a start comment delimiter. When it finds one, it puts a '#' in front of it, then one at the start of each subsequent line until an end comment delimiter is found. The remove block comment script does the opposite.

There are a few other issues to solve, such as having an end delimiter in the middle of a line of code, or a line of code that was already commented before you ran the block comment script, but there are ways around these issues.

I just made this up this morning. It's still too early for me to tell if this is a good idea or just something really silly. :-)

Phemur

Replies are listed 'Best First'.
Re: Perl equivalent of C-style
by Anonymous Monk on May 27, 2002 at 12:43 UTC
    No VI with embedded Perl needed. Or some convoluted procedure. Plain vi works without a problem:

    :.,+3s/^/#/

    This will put a # before the current line, and the next 3 lines.

    Or you could do something like:

    ;<<' */'=~m>>; /* * Multiline * comment. */