It uses one 'feature' of GOTO - you can put a single symbol (if it is not : ) in front of the label and the GOTO will still be able to find it (hope this is not something working only on my machine).Though the leading % in the closing comment can be skipped (and also the one at the end in the closing comment) it triggers my OCD with it's lack of symetry .Also when ':' is the last symbol in the variable name substring or replacement are not started when the variable is used.This looks almost like the comments in the "serious" programming languages. Even all kind of brackets can be used:

A really great idea! It never ceases to amaze me that we can still make progress like this with this good old batch language.

Of course it is a matter of a personal taste

Indeed! I personally favor using :# for comments instead of ::, as the # character is used for comments by most other scripting languages. Using it in batch files like everywhere else, helps me when switching from one language to another.

It's easy to adapt your block comments to use the # character.Note how I also changed the loop-specific ones to use parenthesis instead of brackets. I think this makes it more intuitive as to which macro is for goto comments, and which one is for use in (loops).

:# GOTO macro cannot be used inside for loopfor %%a in (first second) do ( echo first not commented line of the %%a execution %#(% multi line comment %)#% echo second not commented line of the %%a execution)

I found that the closing % is in fact needed at the end of the block, as post #1 is currently written, otherwise giving
The system cannot find the batch label specified - /%

For the same reason, if the first block has the closing % but the second doesn't, infinite loop The second block keeps returning to the label in the first block. Recalling dbenham saying "Although it is generally recommended that :labels are unique within a batch script, it really is OK to embed multiple comments like this within the same batch script" I was curious how it might resolve the "ambiguity". It would appear (and seems logical) that goto looks "downward" for a label, then wraps around to the top of the file if not found below the goto, which is consistent with the infinite loop's progression.

OTOH I found, as you suggested, that the opening % can be omitted at the end of the block, though I agree with you in preference for "symmetry."

All of that is based on your definition
set "/:=goto :/%%"

IF instead the definition is
set "/:=goto :/%"
then you can (and should) omit the closing % at the end of blocks ( %:/ works ) but I agree with you to use the first set definition, and just close with %:/%.

I've been told that I write long posts and smart important people may grow weary reading them. I hope that everything above is of interest or is meaningful to someone, and if not, I apologize. I could have just said "Hey npoc, the closing % is actually needed on post 1" but thought I could add more value. Anyway, stop reading now However, for the intensely curious minds that enjoy trivial details and anecdotes:

I tested the first /: example in post #1 above, saved as COMM_BLK.BAT and run from a command line.
A curious thing happened; after running, I typed the letter C and F8 key.
On Windows 7 it retrieves the command line normally.
On XP SP3 hitting C and F8 does not retrieve it. I wonder why. However you can still up-arrow to the command history item, and it does show in F7. (Microsoft Windows XP [Version 5.1.2600])
However if I renamed from COMM_BLK.BAT to COMM_BAK.BAT, then C and F8 gets it normally in XP. Just curious; maybe a small former bug.

set :=goto %%
%:%
comment lines
...
a little weird that comment opening and closing symbol are identical,
but you can do this also in C with /*/ ... /*/
%:%

This works because searching for a labels happens in a very early phase of the "parser" (for me, a too ambitious denomination in the context of cmd.exe).

Another comment related question: It seems to me that outside of ()-blocks a plain ')' at the beginning of a line works like '::' (with the same restrictions). Any experiences if this assumption is correct?

Another comment related question: It seems to me that outside of ()-blocks a plain ')' at the beginning of a line works like '::' (with the same restrictions). Any experiences if this assumption is correct?

Absolutely, although the restrictions are quite different from those for ::

If the parenthesis counter is 0 and the parser is looking for a command, then ) functions similar to a REM statement as long as it is immediately followed by a token delimiter, special character, newline, or end-of-file

All special characters lose their meaning except ^ (line concatenation is possible)

Once the end of the logical line is reached, the entire "command" is discarded.

@echo off
) This is a comment
)=This is a comment
),This is a comment
);This is a comment
)>This is a comment
)<This is a comment
)|This is a comment
)&This is a comment
echo OK & ) OK is printed and the rest is a comment
) This multiline comment^
works just fine!

But the following attempt at a comment fails because the character following the ) is not acceptable:

Multiple-line comments in batch scripts is certainly the interesting topic. Time ago I was inspired to implement them using internal facilities of the batch interpreter. I have thoroughly read this thread and other links to SO pages. To be honest, all the options with macros like %[:% and %:]% and others are variations (or syntax sugar) of the basic structure. In my opinion this is the best attempt to enter multiline comments to batch script

I found couple of limitations:
-- blank lines after :label within these structures are not allowed and throw error "The syntax of the command is incorrect."
-- some problems with closing parentheses if they are not consistent. The exception is the same "The syntax of the command is incorrect."

Interesting idea, but I don't think I would use it. I like being able to differentiate comment begin from comment end.

I agree. I only enjoyed that it is possible to use identical symbols for start and end of a comment .

My proposal can also make problems when I use syntax highlighting im Vim: It's possible to define a syntax region with identical start and end symbols and even to replace them (by conceal) with different (!) characters (e. g. '{' and '}'). But the highlighting can fail depending on your position in the file, because Vim (and I think other editors too) only parse a limited part of the file for syntax recognition.

By the way, another possibility (in a sense similar to /* ... */) would be to use