9

It doesn't look like there is (just grey code blocks), but perhaps I am missing a way to trigger it.

  • 2
    According to this, no, there isn't. – Robert Harvey Nov 13 '13 at 23:10
  • Your command prompt doesn't even syntax highlight DOS commands. Why would you need an editor to color code that doesn't even have a defined set of colors? Just use <!-- language: lang-none --> and be done with it... – Aaron Bertrand Nov 14 '13 at 2:37
  • 6
    Aaron: True, but most people's bash shells don't colorize anything either, yet there is a highlighter for bash. – Matt J. Nov 14 '13 at 7:33
  • @AaronBertrand my terminal has the option to colorized special words even though the shell itself has no similar function – phuclv Jan 8 '17 at 5:27
  • @AaronBertrand powershell does highlight the commands, unlike cmd.exe – phuclv Nov 29 '17 at 13:40
6

Use

<!-- language: lang-vb -->

Example

rem this is a comment
set here="is a string with spaces"
rem here are some keywords
call zulu
date zulu
do zulu
else zulu
erase zulu
exit zulu
for zulu
goto zulu
if zulu
in zulu
not zulu
-2

You can use

<!-- language: lang-dos -->

Sample output:

@echo off
Setlocal EnableDelayedExpansion
cd %myfolder%
find "sometext" myfile.txt

for /F %%F in (filelist.txt) do (
    set filesize=%%~zF

    if !filesize! GEQ 1000 (
        echo %%F skipped
    ) else (
        copy "%%F" "D:\"
        if errorlevel 1 goto :end
        echo %%F copied
    )
)
:end

However it has some quirks. The most common one is that it assumes the escape character is backslash \. As a result if a quoted folder path ends with \ it'll think the string hasn't end like you saw above, and everything follows will be red like a string. Hence you should avoid ending the string with backslash if possible. Or you can just put another quote in a comment as a workaround like this

copy "%%F" "D:\"
rem This line will be red, because the highlighter thinks
rem the backslash is used for embedding quotes in strings
rem This dummy quote " will end it
rem and things will becomes normal after the quote as you can see
if errorlevel 1 goto :end
echo %%F copied
:end

It also lacks highlighting for many commands

set path="path\with\spaces\" & :: Dummy quote " can also be inlined like this
:: another comment
rem here are some keywords
call zulu
date zulu
do zulu
else zulu
erase zulu
exit zulu
for zulu
goto zulu
if zulu
in zulu
not zulu
  • 1
    The glitches you see are because you're just triggering the default highlighter. (That is, lang-dos is not any better than lang-doodly-fluffer for this purpose.) It has nothing to do with any cmd-specific parsing, because the highlighter has no idea how to do that. – Nathan Tuggy Jan 8 '17 at 7:09
  • @NathanTuggy there's no highlighter for batch file and I have no idea how to trigger the default highligher but this definite works better than nothing or lang-none – phuclv Jan 8 '17 at 8:03
  • 1
    Feeding it random unrecognized lang-* entries is how you trigger it. The key is that they are unrecognized, but this post implies that the choice of dos is somehow significant. It isn't. – Nathan Tuggy Jan 8 '17 at 8:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .