5

Yes, I'm aware of what :h smarttab says, but I still cannot figure it out.

" My vimrc
set backspace=indent,eol,start
set tabstop=8 " I always keep this 8
set shiftwidth=4
set softtabstop=-1 " To use the width of `shiftwidth`
set expandtab
set smarttab

When on, a <Tab> in front of a line inserts blanks according to shiftwidth. tabstop or softtabstop is used in other places. A <BS> will delete a shiftwidth worth of space at the start of the line.

When off, a <Tab> always inserts blanks according to tabstop or softtabstop. shiftwidth is only used for shifting text left or right shift-left-right.

But I observe the same behavior even if smarttab is off. Pressing the Tab key inserts 4 spaces, and pressing the Backspace deletes 4 spaces. Why does it happen? What is the reason to use smarttab then?

1 Answer 1

6

What is the reason to use smarttab then?

As it is written in help, when smarttab is off, softtabstop is used everywhere including line start. However, if softtabstop is equal to -1 then it is set to shiftwidth anyway. Hence there'll be no difference in setting smarttab on or off.

In other words, smarttab is only meaningful if both set expandtab and softtabstop differs from shiftwidth. But normally it's not the case and we don't need smarttab.

4
  • ... if both set expandtab and softtabstop differs from shiftwidth -- I'm not sure I understand the mention of expandtab in this context. Since expandtab is a Boolean option, its value is always different from the value of shiftwidth.
    – james
    Commented Sep 12, 2021 at 15:53
  • @james if set expandtab.
    – Matt
    Commented Sep 12, 2021 at 16:00
  • Probably you mean "if expandtab is set and if, at the same time, softtabstop differs from shiftwidth"? I'm sorry, although my name here is "James" (which is an English name), I'm not a native English speaker.
    – james
    Commented Sep 12, 2021 at 16:06
  • 1
    @james Me neither. I simply hope that I put it in a way that makes sense. Yes, if et is set and sts is not equal to sw.
    – Matt
    Commented Sep 12, 2021 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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