Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Sunday December 03, 2006
02:17 AM

Hooray for Hard Tabs!

[ #31790 ]

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?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
    • 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?

      • 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 [vim.org], but I can’t unearth it now.

        • There is some info at :h 'ts' that explains it.
          • As far as I can tell, the magic here is

            'softtabstop' 'sts'

            I have expandtab set, and shiftwidth, tabstop et al. are all set to four. Leaving all that constant, and setting sts=4, vim will now backspace over tabs. It won't treat tabs as single chars for x, but you can always I<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.

  • Yep, tabs are hard. :)
  • set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab
    --

    --
    xoa

  • I've been using vi and vi-clones for more than 20 years. And while my favourite vi-clone doesn't insert tabs (but spaces), I've seldomly the need to delete tabs. Neither in vi or in a vi-clone. As pointed out elsewhere, in insert mode, ^D removes an indent. And in command mode, < does so. And that's a command that takes a movement as argument, so doubling deletes an indent from the current line (<<), to delete indents from 7 lines I do 7<< and <} deletes indents from the current line to th