tabs in vi

Mike Van Pelt mvp at v7fs1.UUCP
Thu Aug 24 11:26:42 AEST 1989


> Is there a way to make it so that when ever I hit the TAB key
> in 'vi' that I get 4 spaces rather than an actual tab?  I would
> rather not have to run expand after running vi, as I would only
> want to do that if I actually changed the file.

The :map! ^V^V<tab> ^V^V<sp><sp><sp><sp> and set shiftwidth=4 solution
that's been mentioned does part of it.  What a lot of people seem to be
missing is that YOU DON'T WANT ANY TABS AT ALL in the output text --
just spaces, as in the output from expand.  To do that, set tabstop=99
in your .exrc file, and autoindent will put in spaces instead of tabs
at the beginning of your lines. (Assuming lines don't grow beyond 99
columns, anyway...)  Then, when you edit someone else's file with tabs
in it, you'll see awful garbage, and have to run the whole file through
expand -4.  You'll only need to do this once, from then on, the file
will be nice and tabless.

A quick way to do this is :$ to the end of the file, set a mark with
ma, :0 back to the top, then type  !'aexpand -4<cr>    This runs the
text of the file through expand, deletes it all, then replaces it with
the output from expand.  Note, if you mistype the expand command, it
will replace all your text with the error message.  The u command
will get it back... just make sure caps lock didn't get set somehow,
as upper-case U will make it impossible to undo the command.  (This one
bites me every so often... I hate the F1 caps-lock on the Sun!!!!)
-- 
Mike Van Pelt                     "Beware the first release, my son,
Headland Technology/Video 7        and shun the frumious 1.0"
...ames!vsi1!v7fs1!mvp



More information about the Comp.unix.questions mailing list