Is it possible to set a tabstop (number of spaces per tab) for the more and less commands? In vi, I've added this line to .vimrc

set tabstop=4

However when I read through a file with more it still uses 8 spaces per tab

$ more style.css
div {
        width: 100%;

Would this be something I could configure in .bashrc or a similar file?

  • You say tabstop then you say spaces per tab. Those are two different things. Which is it you are after? Tab stops or tab spaces? – NOYB Sep 7 at 19:58

from man less:

  -xn,... or --tabs=n,...
         Sets tab stops.  If only one n is specified, tab stops are set at 
         multiples of n.  If multiple values separated by commas are specified,
         tab stops are  set  at  those positions, and then continue with the same
         spacing as the last two.  For example, -x9,17 will set tabs at positions
         9, 17, 25, 33, etc.  The default for n is 8.

The man page also describes how to set default options for less using setenv or export. Adding LESS="-x4";export LESS to your ~/.bashrc should do the trick

| improve this answer | |
  • Sorry it took a while to accept this, I was hoping for an answer for more since I usually use that out of habit. Since less has other benefits anyway, I'll just try to use less more :) – andrewtweber Oct 14 '15 at 21:48

I think it's not a property of bash (or zsh, csh... and other shell). It's property of terminal which showed the output.

You can use expand command to convert tab to number of spaces. From expand man page:

-t, --tabs=NUMBER
              have tabs NUMBER characters apart, not 8

So you will do like this:

$ cat test.tabs
a        b        c

$ expand -t 4 test.tabs
a    b    c
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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