tabs in vi

Socrates kevin at client1.DRETOR.UUCP
Thu Aug 24 01:24:33 AEST 1989


In article <36790001 at hpindwa.HP.COM> sgordon at hpindwa.HP.COM (Shaun Gordon) writes:
>> 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.
>
>While inside vi you can type a colon to get to the command line and then enter:
>
>set tabstop=4
>
This does not appear to be what is desired here.  I interpret this as one
of the standard vi gripes when indenting by half-tabs.  (If you use the
above solution then what appears fine from within vi expands to tabstops at
8 columns by cat, more, etc...)

There is no easy solution for this, that I have found, however there is a
kludge that you can insert into your .exrc.  It involves the :map!
functions.  :map allows you to redefine key meanings, and the ! means that
the new definitions apply only within insert mode.  The solution I use is
to redefine a tab character as four spaces.

Only one problem with direct implementation: vi won't recognize the four
spaces as existing since it (nicely?) removes whitespace from definitions.
To get around this I exit insert mode, then reenter with four spaces
entered immediately.  There is no noticeable slowdown to perform these
extra operations.  (I'm using vi on a Sun 3/50 BSD4.2)  Here then is the
command line to do it:

     :map! <CTRL-V><CTRL-V><CTRL-I> <CTRL-V><ESCAPE>a     (ends with 4 spaces)

Hope this is what you are after.



-- 
--- Kevin Picott   NTT Systems, Inc., Toronto, Ontario
    "There can be no offense where none is taken" - Japanese Proverb

    kevin at zorac.dciem.dnd.ca, or on some sites kevin at zorac.ARPA



More information about the Comp.unix.questions mailing list