in reply to Re: The classical <TAB> issue
in thread The classical TAB issue

You could set it to output spaces instead of a literal \t, but I don't like having to do 8x or 4x to remove a level of indentation (in vi) when I can use simple x instead.
Learn your vi. Assuming your cursor is on the code, and not on the indent, using the 'x' method to remove a tab takes you two key strokes: 0x, or ^X. But there's another way, that will work with spaces as well, doesn't require the cursor to be on the indentation, and which is sensitive to movement commands (so you can outdent regions): <<. And to indent: >>.
sub foo { <TAB>my ($bar, $baz) = @_; <TAB>if($bar) { <TAB><TAB>return $baz; <TAB>} <TAB>return 0; }
If I have tabstop set to 8 and someone else has it set to 4, it will look right in both cases.
Sure, in this simple example it will. But suppose you have your tabstop set to 8, write the above code, check it in to source control, and someone with a tabstop set to 4 checks it out, and modifies it as follows:
sub foo { <TAB>my ($bar, $baz) = @_; <TAB>if($bar) { <TAB><TAB>if (fuzzle ()) { <TAB><TAB><TAB># Expression taking 60 characters. <TAB><TAB>} <TAB><TAB>return $baz; <TAB>} <TAB>return 0; }
Looks great, with an 8 character margin on the right to spare, so it fits in the pleasing "72 character" width, and certainly it fits in the default 80 character window.

The code is checked in, and you check it out again. You look at the code in your 80 character window, and the last four characters of the new code will appear wrapped to the next line. Yuck!

If even becomes much yuckier if the coding guideline says "4 character indent", and some people use an 8 character tab-stop, and some use a 4 character tab-stop. Say the current block has <TAB> as indentation and two if/else statements are added, by different programmers. One will use <TAB><TAB> as indentation - the other <TAB><SP><SP><SP><SP>. Fun! Fun! Fun!

Abigail

Replies are listed 'Best First'.
Re: Re: <blocThe classical <TAB> issue
by hardburn (Abbot) on Apr 06, 2004 at 15:50 UTC

    Assuming your cursor is on the code, and not on the indent, using the 'x' method to remove a tab takes you two key strokes: 0x, or ^X.

    Hrm? A simple x has always worked for me, but then I also use vim with its nearly-modeless settings whenever I can get away with it. (I probably should have specified this above). Admittedly, removing any sizeable block of indentation can be done faster with a search-and-replace on those lines anyway.

    Sure, in this simple example it will.

    And that's exactly what I was trying to show: a simple example where any sane value of tab settings will work. There are probably more cases where they won't work than everyone on this site could list.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      Hrm? A simple x has always worked for me
      In any vi I've encountered the past 20 years, 'x' deletes the character under the cursor. So, if your cursor is on code, you first need to move the cursor to the indent. Hence '0x' to move the cursor to the first column, and delete that character, or '^X', which moves the cursor to the first non-white space character on the line, and then deletes the character before it.

      Abigail