# Differ between 'softtabstop' and 'expandtab' options in function

If you use of softtabstop and expandtab options in vary ways and try to test them, these options are opposite in function (at least as I think).

et option will produce the appropriate number of space when we press TAB key and when we press BS the spaces will delete one by one in the other hand when we set sts and press BS it will delete a tab (not spaces one by one). Thus setting et and sts option in vimrc together isn't a good idea because they will break their effect together.

Now am I thinking right? (If not please let me know how they are differ in function and behaviour.)

## 1 Answer

No. sts and et options have distinct functions and are not mutually exclusive.

With softtabstop and noexpandtab, vim will insert a mixture of tabs and spaces, to make it up to the sts value. How many tabs are inserted depends on tabstop, for example ts=3, sts=4, vim will insert one tab and one space, for a total of 4 spaces-equivalent.

With softtabstop and expandtab, vim will insert the sts number of spaces.

In both cases, backspacing still works as though you had inserted a tab which is sts wide.

vim's behavior and number of indent-related options is perhaps surprising, but this is not merely an "academic" discussion. For a real example, see the vim source code, which uses indents of four spaces-equivalent but tabstop=8. So, lines indented once get four spaces in front, lines indented twice get a tab, and lines indented thrice get a tab then four spaces. In this case, one might prefer set sts=4 sw=4 ts=8. When pressing <tab> twice, vim will insert a real tab instead of spaces. Note also this answer does not discuss interaction with the shiftwidth or smarttab options.