I like to indent my shell scripts with two spaces instead of a TAB. So, I set
setlocal shiftwidth=2 in
~/.vim/after/ftplugin/sh.vim. It works, but I noticed that when the indentation level gets greater than 8 spaces, Vim replaces them with a tab. So, I also added "setlocal expandtab" in this file.
Unfortunately, this replaces all tabs by 8 spaces, even the ones inserted when I press the TAB key.
I'm looking for suitable settings to always have indentation (automatic or manual) composed of spaces only, but still insert a real tab when I press the TAB key.
On other Q&A, I found functions to toggle between spaces and tabs, but I'm looking for a solution which doesn't involve any kind of toggling.
Likewise, sticking with
shiftwidth only and use
:retab from time to time after momentarily enabling
expandtab would not be a suitable solution (let alone the fact that since tabs and spaces are indistinguishable on screen, I wouldn't know when a file needs to be "retabbed").