The "weird" REM %~ "error" is not limited to XP. It is present in all modern versions of Windows that use CMD.EXE. After reading your question, I wrote a Simon from SS64 note to clarify this issue. REM can also fail if var exists, and you have rem %var:= .
So technically, there is no reliable safe blind use of REM.
But, if you are ready to accept the risk of fatal% expansion, most of your listed hacks are safe to use, but only if the line includes at least one additional command via & or && .
REM. It will never be safe in any situation if there is a file named REM (without extension).
The directory partitions \ and / always fail if the current folder contains a file called test.bat and you use REM\..\test.bat .
Similarly, REM:\..\test.bat always fails.
Each of the other hacks can fail autonomously in a similar situation. For example, REM^[tab]\..\test.bat crashes autonomously, but works when combined with another command. This is the only type of situation I have found where + , [ , ] or ^[tab] can fail.
There are additional cases where some of the other hacks may fail.
Any character in the set C ( ^[space] , ^, remC.bat ^= )) that is valid in file names can fail offline if remC.bat exists. For example, the following failures are autonomous:
rem^ Fails if "rem .bat" exists
However, they are all safe when combined with another command:
echo OK&rem^ This is safe rem^ This is safe &echo OK
Temporary update
Some of the above errors are incorrect. Research continues at http://www.dostips.com/forum/viewtopic.php?f=3&t=6895&p=44813#p44813 .
I believe that the following simple forms that are guaranteed to work in all cases (excluding the invalid% extension)
REM: At least one space (or other token delimiter) must be after : REM\ At least one space (or other token delimiter) must be after \ REM/ At least one space (or other token delimiter) must be after / REM^[tab] At lease one space (or other token delimiter) must be after [tab]
But I will not correct earlier information until the dust calms down.
Complete Temporary Update
My favorite way to use inline comments is to use impossible variables. Only dynamic pseudo variables can contain = in the name, and no variable name can ever contain two = . Therefore, I like to use %= Remark goes here =% . The beauty of this form is that it can be used almost everywhere with impunity if the comment does not contain % or : It can even be safely used in square brackets.
for %%F in (*) do ( %= Comment within code block =% %= 2nd comment within code block =% FINDSTR /B %=Must match beginning of line=% "string" %= Search string =% "%%F" %= File to search =% )