1

I've created 2 files named tab1 and tab2. For tab1, I've used normal tab which is using 8 space by default.

Meanwhile for tab2, I've changed it using :set tabstop=4 command.

I've also tried :set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

It was working fine in vi, instead of having 8 blank spaces, now I have 4 blank spaces for tab.

inside vi

123456789
    2   
~                                                                                                          
:set tabstop=4   

However, when I view the files again with cat command, it seems like both commands didn't help at all.

Please let me know how to make this changes persistent even outside vi when viewing it using other utilities such as cat.

outside vi

123456789
user@host:~# cat tab1
        1
user@host:~# cat tab2
        2
user@host:~# 

My goal is to have 4 spaces when using tab permanently even outside vi editor like this.

Please let me know if you have a solution for this. Thanks

123456789
user@host:~# cat tab1
        1
user@host:~# cat tab2
    2
user@host:~# 
123456789
Charlotte Russell
  • 1,355
  • 1
  • 13
  • 16
  • Possible duplicate of [Redefine tab as 4 spaces](https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces) – yuri kilochek Aug 20 '17 at 08:42
  • @yurikilochek, it's not duplicate. `:set tabstop=4` only works inside vi, not outside ... see my example above. – Charlotte Russell Aug 20 '17 at 08:46
  • Read the accepted answer carefully, It explains how to make your TAB keypresses result in 4 spaces in actual file. `tabstop` only changes how wide the tab character is rendered in the editor. – yuri kilochek Aug 20 '17 at 08:50
  • I was reading that before I post the question here, however I didn't see the answer. Please point it here if I missed it. Tq – Charlotte Russell Aug 20 '17 at 08:53
  • [For indents that consist of 4 space characters but are entered with the tab key: `set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab`](https://stackoverflow.com/a/1878983/1554020). Or do you perhaps mean you want tabs to stay actual tabs but be rendered with 4 spaces everywhere? That is impossible without configuring 'everywhere' too. – yuri kilochek Aug 20 '17 at 08:58
  • `:set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab` wasn't the answer. I already tried that before I post it here. As I said in my post, it only works inside vi editor, not outside. My goal is to have it with 4 spaces even when viewing it with `cat` command – Charlotte Russell Aug 20 '17 at 09:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152371/discussion-between-yuri-kilochek-and-charlotte-russell). – yuri kilochek Aug 20 '17 at 09:01

1 Answers1

1

You can set the tabstop width in terminal with tabs(1), e.g.:

$ tabs -4
$ cat tab1
    1
clemens
  • 16,716
  • 11
  • 50
  • 65