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.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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
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
= in the
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.
@echo off setlocal EnableDelayedExpansion for /f "usebackq tokens=* delims=" %%a in (`hg diff`) do ( set __temp=%%a echo !__temp: = ! ) endlocal
I'm not sure where this 8 chars are coming from for you, but I have always had 4 chars when typing any text file out from cmd.exe using TYPE or COPY, it may be that the output is double-tabbed. In keeping with traditional DOS, the width of a TAB is 4 chars, there are MANY command line tools out there that rely on this, that is the most likely reason there is no way to change it as far as I know (if there was it would be somewhere in the registry, but i never saw it), unless you decompile/recompile cmd.exe. My suggestion is to write a script or console tool that prints the output to the console screen for you, interpreting the tabs however you want or find a tool like this already made somewhere.
This isn't a general solution, but since you happened to ask about 'hg diff', and it happened to show up in my Google query.. :)
So the way I solved the tab problem for this particular case was to use less.exe. I happened to be using it already, actually, but it just needed an extra parameter. Here's a bit of my hgrc (simplified):
[extensions] pager = [pager] attend = annotate, cat, diff, export, glog, help, log, status pager = path\to\less.exe --quit-if-one-screen --raw-control-chars --tabs=4 hg16mode = yes