Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Are you sure there isn't an option in Mercurial to set the tab width for diff? (Don't use Mercurial, but I know you can certainly do it with git and I would have expected every almost programmer's editor and viewer to be configurable). –  sgmoore May 16 '12 at 17:18
    
No, I couldn't find one. I may try to write an extension for it. But I thought it would be worth checking if there wasn't a simple solution in cmd first. –  Gieron May 16 '12 at 18:38

3 Answers 3

up vote 3 down vote accepted

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
share|improve this answer
    
I find it interesting that you didn't need to use usebackq and then hg diff ... cool solution. –  jftuga May 16 '12 at 11:55
1  
@jftuga usebackq is only necessary if the command to be executed contains quotes (') itself. If he needs to use single quotes in his command, then yes, the usebackq option is needed and backquotes should be used instead of quotes around the command. But that means backquotes cannot be used in the command... hmm... pick one ;) –  Bob May 16 '12 at 11:57
    
Great tip! Thanks for the explanation. I did not know the details of usebackq. –  jftuga May 16 '12 at 12:04
    
This is the primary reason I favor spaces over tabs, wrapping all of my hg, svn, git commands in this manner just so my diffs, blames and cats have the same indentation as they do in my editor seems silly. But kudos to @Bob for the clever solution. I suppose my alternative could be to set tab indention to 8 spaces in my editor... –  Marcus Pope Sep 18 '12 at 18:15

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.

share|improve this answer
2  
I disagree, as does every version of every operating system (dos, windows, linux, osx etc) that I have ever used and and so does en.wikipedia.org/wiki/Tab_key which says '... de facto standardized at every multiple of 8 characters horizontally'. –  sgmoore May 16 '12 at 17:06

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.