4

Are this:

set noexpandtab
set shiftwidth=4
set tabstop=4
set softtabstop=0

..and this:

set noexpandtab
set shiftwidth=4
set tabstop=4
set softtabstop=4

..exactly the same? I thought that if softtabstop=0, then nothing happens if Tab is pressed, but this does not seem to be the case.

  • What made you think sts=0 prevents <Tab> from working? – romainl Sep 3 '16 at 7:42
  • @romainl As I understood it, tabstop simply defines the width of the tab character(for example ts=4 means that it is four columns wide) while softtabstop actually defines amount of tabs and spaces inserted if <Tab> key is pressed. For example if ts=4 and sts=1 and one presses the <Tab> key, then only a single space character is inserted. Now if one makes another three spaces, then those are converted to single tab. This made me think that if sts=0, then nothing happens if <Tab> is pressed. – Martin Sep 3 '16 at 11:15
  • Set softtabstop to -1, shiftwidth to 0 and both options will then follow, whatever your tabstop setting is – Christian Brabandt Sep 3 '16 at 11:29
  • @ChristianBrabandt Thanks for this tip! However, I don't mind configuring all three. I was simply wondering why pressing <Tab> key inserts tab character or spaces(if expandtab is on) if sts=0. After all, sts controls how many columns vim uses when one hits <Tab> in insert mode and if sts=0, then IMHO it's logical to expect no characters when <Tab> key is pressed. – Martin Sep 3 '16 at 17:22
  • 1
    The only difference is when backspacing over a line that already had spaces for indentation. – Antony Sep 5 '16 at 19:07
4

Think of 'softtabstop' as an additional control over 'tabstop', allowing you to reach indents "in between" tab stops.

With your indent setting, you don't actually need that, so the value of 'softtabstop' doesn't really matter: You can set it to 0, turning this off, set this equal to 'tabstop', in which case the effect is the same as off, or :set softtabstop=-1 shiftwidth=0, and both will follow the 'tabstop' setting.

5

As mentioned in :h softtabstop, the softtabstop indicates how many columns vim uses when you enter <Tab> in insert mode. Although it performs like <Tab> inserted, in fact, the vim mixes <BS> or <Tab> for that.

If you hit <Tab> in insert mode, the vim will act like:

if set expandtab
   always uses <BS>
else
   if softtabstop == 0
       always uses <Tab> // the number of columns is equal to tabstop
   else if softtabstop < 0
       the number of columns for <Tab> is equal to :shiftwidth
       && uses a mix of <BS> and <Tab>
   else
       uses a mix of <BS> and <Tab>
   end
end

For example,

In :set noexpandtab shiftwidth=4 tabstop=4 softtabstop=2 case, the value of tabstop is large than the value of softtabstop, the vim will use two <BS> chars to represent one hit <Tab>.

In :set noexpandtab shiftwidth=4 tabstop=2 softtabstop=2 case, the value of tabstop is equal to the value of softtabstop, the vim will use one <Tab> char to perform one hit <Tab>.

In :set noexpandtab shiftwidth=4 tabstop=2 softtabstop=3 case, the value of tabstop is less than the value of softtabstop, the vim will use one <Tab> char and one <BS> char to perform one hit <Tab>.

In :set noexpandtab shiftwidth=4 tabstop=2 softtabstop=0 case, the value of softtabstop is zero, the vim always uses <Tab>.

Therefore, in your case, :set noexpandtab shiftwidth=4 tabstop=4 softtabstop=0 does equal to :set noexpandtab shiftwidth=4 tabstop=4 softtabstop=4.

In my opinion, it's better to use tabstop == softtabstop if you want to handle with <Tab>. Because the vim will not use a mix solution.

  • 1
    This is NOT an answer. This might serve as a good comment, but I strongly encourage you to either delete the answer or write out the answer properly. – Karl Yngve Lervåg Sep 7 '16 at 6:08
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – James Sep 7 '16 at 6:13
  • 1
    @KarlYngveLervåg Thank you for remind me. I have updated the answer. – Wei Fu Sep 7 '16 at 7:39
  • @DJMcMayhem I got your point. It make senses. I updated the answer. Thanks – Wei Fu Sep 7 '16 at 7:40

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.