I understand and appreciate all of the arguments for using spaces instead of hard tabs in source code, but there's one drawback I just can't escape. A tab is a single character you can delete with one backspace or skip over with one left or right cursor keypress.
More people would complain if Enter produced carriage return plus newline (as it does now) but your editor treated both separately.
How do I make Vim respect soft tabs as a single entity?
Re:Easy
chromatic on 2006-12-03T08:26:21
I already have
:set backspace=indent,eol,start
. That's still not everything I want. Backspace does back up past autoindent, which is okay, but that's not the only thing I want. I want Vim to treat tabs as four spaces when it saves the file, but as single characters when I move around in or edit the file.Did I read the help text incorrectly?
Re:Easy
Aristotle on 2006-12-03T09:15:47
Ah, OK. There’s no builtin way of doing that to my knowledge. I could swear I saw a way to do this with scripting in either the scripts or tips section of vim.org, but I can’t unearth it now.
# vim: set ts=8 sts=4 sw=4 noet:
mr_bean on 2006-12-03T09:39:01
There is some info at:h 'ts' that explains it. Re:# vim: set ts=8 sts=4 sw=4 noet:
fishbot on 2006-12-03T16:25:02
As far as I can tell, the magic here is
'softtabstop' 'sts'
I have
expandtab
set, andshiftwidth
,tabstop
et al. are all set to four. Leaving all that constant, and settingsts=4
, vim will now backspace over tabs. It won't treat tabs as single chars forx
, but you can alwaysI<BS>
if you are in a leading tab-grouping and want to delete one tab. Of course, at that point you might as well<<
set smarttab
and then BkSpc will remove an entire indent.
Also note that in insert mode Ctrl+T will indent (“tab”) and Ctrl+D will delete an indent. You can press these with the cursor anywhere in a line and the indent will be tweaked at the start of the line.