tabs in vi

Andy Behrens andyb at coat.com
Thu Aug 24 02:09:44 AEST 1989


>In article <36790001 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.

I assume that you simply want to indent the left margin by 4, 8, 12,
etc., spaces.  As has been pointed out, ":set tabstop=4" will not work,
because it redefines the meaning of tabs instead of using spaces.

What you want is

	:set shiftwidth=4	(:set sw=4), possibly combined with
	:set autoindent		(:set ai)

Now, DON'T use the tab key at the left margin; use ^T instead.  Each ^T
will move 4 positions to the right (inserting combinations of tabs and
spaces to get to the correct column).  Each ^D at the left margin will
move 4 positions to the left.

(I suppose you could map TAB into ^T if you wanted to).

As an extra bonus, you can now use the "<" and ">" commands to shift a
previously-typed block of lines left or right.

	>>	will shift 1 line
	6>>	will shift 6 lines
	>}	will shift everything to the end of a paragraph
	>%	if the cursor is over a brace or parenthesis, will shift
		    everything until the matching brace or parenthesis.

--
Live justly, love gently, walk humbly.
					Andy Behrens
					andyb at coat.com

uucp:   {harvard,rutgers,decvax}!dartvax!coat!andyb
bitnet: andyb%coat at dartcms1
Burlington Coat, PO Box 729, Lebanon, N.H. 03766	(603) 448-5000



More information about the Comp.unix.questions mailing list