Set the tab length in cmd.exe

By default tab characters in cmd are written as 8 characters long. Is there any way I can change this to something smaller?

We use tabs for indentation in our code. So diff output from Mercurial (i.e. hg diff) becomes quite horrible to read.


With a batch file you can use line by line string substitution to replace tabs with four spaces:

@echo off

setlocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in ('hg diff') do (
    set __temp=%%a
    echo !__temp:   =    !
)

endlocal

The EnableDelayedExpansion enabled the use of !s and the modification of variables within the for loop.


It appears inserting code into this answer has substituted the tab for three spaces. When you copy this to a batch file, make sure there's an actual tab character between the : and = in the echo line.


If you have single quotes in the command you need to run (I don't actually know the full syntax of hg diff), then you have to surround it with backquotes and enable usebackq. Which means you can't use backquotes in the command you need to run. Pick one.

Backquoted version:

@echo off

setlocal EnableDelayedExpansion

for /f "usebackq tokens=* delims=" %%a in (`hg diff`) do (
    set __temp=%%a
    echo !__temp:   =    !
)

endlocal

I have no idea how can you do what you want, but you could:

  1. change the size of the buffer and window widths to increase the total line space; Cmd Sreen Buffer and Window Size
  2. redirect the output to a file, then read the file with a text editor like Notepad++.

    c:\>hg diff > file.txt