tabs in vi

Shaun Gordon sgordon at hpindwa.HP.COM
Thu Aug 24 08:11:05 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.

Sorry, I misunderstood your question.  I thought that you just wanted to
know how to tab 4 spaces instead of 8.  Kindly ignore my last posting.

To salvage my image as "someone who isn't entirely clueless," I will offer
the following partial (although not very elegent) solution.

First, set the following two options.

    set shiftwidth=4
    set tabstop=200

Now all you have to do is use ^T instead of using the TAB key.  The variable
'shiftwidth' sets the number of spaces to "tab".  You need to set 'tabstop'
to a large number to stop vi from replacing your ^T tabs with real tabs (i.e.
if you had tabstop=8 and shiftwidth=4 and you pressed ^T twice, vi would 
replace your spaces with a real tab.)

Another thing to note is that if you use ^T at the beginning of a line, you
can't use your backspace key to erase one of your "tabs".  You will need to
use ^D to go backwards one tab.

On my version of vi, this solution works, however, I seem to recall that when
I used vi at UC Berkeley, that ^T only worked at the beginning of lines and
wouldn't do anything if you tried to use it if there was anything other than
whitespace to the left of the cursor.  If this is the case, you will not
be able to tab anywhere except before the first character of a line.

If this works, the next step might be to figure out how to map the tab key
to ^T in your .exrc file (I couldn't figure it out.)

Hope this works for you -- please let me know what happens, and if you have any
questions, feel free to mail me.

-Shaun



More information about the Comp.unix.questions mailing list