49

Is it possible for less output to set the tab width to a number X as it is for cat?

2
  • 2
    You don't need to change the tabs length setting to output a file with reduced tab size. Just use expand instead of cat, like so: expand -4 residuum.txt. Commented Jul 30, 2014 at 16:49
  • I just thought I'd drop by to mention that while expand and unexpand are cool, there is also the tabs command. Sadly less seems to ignore or reset what the terminal tabstops are set to. It's in posix: unix.com/man-page/posix/1p/tabs Commented Sep 11, 2023 at 23:04

3 Answers 3

63

Yes, it is possible with less -x or less --tabs, e.g. less -x4 will set the tabwidth to 4.

You can configure defaults with the LESS environment variable, e.g. LESS="-x4".

1
  • 1
    Thanks for your fast response! Didn't find the option. I'll accept your answer as soon as it is possible :)! Commented Jul 30, 2014 at 14:32
36

The less-specific answer has already been given, but a generic solution (for any pager) is to expand the tabs (with space characters) with the expand command before feeding to the pager:

expand -t4 file | pager 
1
  • 1
    Ah ok :), good to know! Works like a charm. Commented Jul 30, 2014 at 14:37
11

Instead of setting the tab width in command line (before you open less). You can also set the tab width within less by typing -x4

2
  • 2
    This is the answer I really needed. Who always knows how wide they want tabs before they even open the file? Commented Dec 5, 2016 at 19:34
  • @guenthmonstr Python programmers ;) 4-wide everywhere baybee! Commented Jun 13 at 3:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.