How to display tabs as 4 spaces in gnome-terminal
Asked Answered
P

7

19

Actually gnome-terminal display tabs as 8 spaces, and this is very annoying when you cat files or view diffs, is there some way to change this permanently?

Prude answered 5/1, 2010 at 11:47 Comment(2)
Seems more a question for superuser.com.Hangbird
Anyone know what package contains this magic "tabs" command on RHEL?Gauguin
P
5

The unique solution I found is to type in terminal:

tabs 5,9,13,17,21,25,29,33,37,41

and append it to ~/.bashrc if you want permanent changes.

PS: This obviously cover up to 10 tab indents.

Prude answered 5/1, 2010 at 14:11 Comment(0)
T
30

Instead of writing out an explicit list of tabstops, you can also use implicit intervals:

tabs -n

This will set tabstops to occur every n columns. For more information, check out the manpage for tabs at http://manpages.ubuntu.com/manpages/maverick/en/man1/tabs.1.html.

Thunderstone answered 26/4, 2011 at 16:27 Comment(3)
This doesn't work; it sets the first tab stop at n rather than at 1, even though the documentation states otherwise. This is a bug in tabs.Eyeglass
Well, it does for me.Vittoria
When I placed this in .bashrc, I had some weird problems with it not fully taking effect until next login, even though this should not be necessary.Alkali
P
5

The unique solution I found is to type in terminal:

tabs 5,9,13,17,21,25,29,33,37,41

and append it to ~/.bashrc if you want permanent changes.

PS: This obviously cover up to 10 tab indents.

Prude answered 5/1, 2010 at 14:11 Comment(0)
B
3

You need to set the tabwidth on the underlying tty, not in gnome-terminal itself.

Theoretically, you should be able to use 'setterm -regtabs 4' to set the tabwidth to 4 in your .bashrc.

Doesn't seem to be working on my linux distro, but it works when I ssh from a remote system.

The easiest way to reset the tabwidth to 8 is to use 'tabs -8' (tabs -d8 to get a visual of the change).

Batista answered 5/1, 2010 at 12:12 Comment(1)
Setterm only works in TTY, so I apply 'tabs', see the next answer. (I do not know it before, so thanks ;D )Prude
P
3

The problem with doing it as "tabs -4" is that the first tab stop is off by one (at least on my system). If I type in "tabs -4", for example, the first tab stop will start in the 4th column with 3 blank spaces in front of it instead of 4. Subsequent tab stops will all be correctly separated by 4 spaces. A workaround to this is to specify the tab stops like so:

tabs 1,+4,+4,+4,+4,...
Philologian answered 10/3, 2013 at 1:23 Comment(0)
C
3

If you're using bash, this is what I have in my ~/.bashrc:

# set tabs to width TABWIDTH
TABWIDTH=4
# for less(1) the option -x4 was added (see above);
# other programs may need their own flags
setterm -regtabs ${TABWIDTH} </dev/tty
tabs -0 </dev/tty
# this erroneously imho sets the first tab at offset 3, not offset 4:
#tabs 1,+${TABWIDTH} </dev/tty
# this works:
tabs 1`for i in {0..40}; do echo -n ",+${TABWIDTH}"; done`
unset TABWIDTH

Note the backticks around the 'for ... done' ditty.

edit: The last '+4' before the 'done' statement should of course have been +${TABWIDTH}.

Cloddish answered 8/12, 2013 at 13:26 Comment(1)
For me this prints setterm: terminal xterm-256color does not support --regtabs whenever I open a terminal. Also all but the penultimate line were unnecessary, for both graphical and virtual consoles.Alkali
M
2

You can also do tabs -4 and it will set a tab stop every 4th column.

Mannered answered 2/1, 2012 at 20:37 Comment(0)
E
0

tabs 1,5,9,13,17,21,25,etc doesn't appear to work entirely correctly. On input, when backspacing over a tab, gnome-terminal goes back 8 spaces, not four. Looks like there's a gnome-terminal bug here. (Note: you won't see this if typing into the shell, because it usurps tabs for file completion. You have to first run cat or dc or some other command that doesn't arrogate tab characters for its own purposes.)

Earthlight answered 10/8, 2016 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.