[comp.unix.questions] Replacing tabs in vi

randy@tekla.UUCP (Randy Gibbons) (01/15/87)

This seems like a likely group, hope it doesn't offend too many.

Is there a way in vi to have spaces rather than tabs placed in the
text.  I know about tabstops and shiftwidth and that's not really
what I want.  I've also written a filter which replaces tabs with
the appropriate number of spaces but this too falls short of my goal.

What I'd really like it to just have vi place the correct number of
spaces rather than tabs in the file.

Yet another option for oh so simple a program!

While I'm at it,.....  Does MH_MAIL have an interactive mode which allows
me to look at a list of mail messages and after each one give a
command describing what to do with that piece of mail (refile, rmm,
etc)?  Something sort of like rn.

andyb@dartvax.UUCP (01/16/87)

> Is there a way in vi to have spaces rather than tabs placed in the
> text.  

First convert any tabs that are already in the file to spaces.  Then
set tabstops to a fairly large number.  (It should be larger than
number of spaces at the front of the most deeply indented line you
expect to type).  I use ts=60.

The tab key on your keyboard will still insert tabs into the file, but
at the start of a line you can use ^T and ^D to indent or undent.

					Andy Behrens

was@hplsdlw.HP.COM (William A. Stubblebine) (01/19/87)

randy@tekla.UUCP (Randy Gibbons) asks:

> Is there a way in vi to have spaces rather than tabs placed in the
text.

Unfortunately, vi has an annoying tendency to auto-indent using tabs.  I
don't know of a way to disable this (mis) feature.  However, once the
tabe are in the file, you can remove them (i.e., replace with the
equivalent number of spaces) easily using the following vi commands:

	1G		(top of file)
	!Gcol -x	(replace contents of file with detabbed output
			of col -x)
		
Of course, in the above example, any motion symbol (H,L,}, etc.)  can be
substituted for G to localize the substitution


                                Bill Stubblebine
                                Hewlett-Packard Logic Systems Div.
                                1900 Garden of the Gods Rd.
                                Colorado Springs, Co. 80907
                                ...!ihnp4!hpfcla!hpldola!was
                                (303) 590-3072

wcs@ho95e.UUCP (01/23/87)

In article <3050001@hplsdlw.HP.COM> was@hplsdlw.UUCP writes:
>randy@tekla.UUCP (Randy Gibbons) asks:
>> Is there a way in vi to have spaces rather than tabs placed in the
>text.
>Unfortunately, vi has an annoying tendency to auto-indent using tabs.  I
>don't know of a way to disable this (mis) feature.  However, once the
>tabs are in the file, you can remove them [.......]
> .....	!Gcol -x    (replace contents of file with detabbed output of col -x)

(I happen to think tabs are a "good thing"; I'd much rather work in vi
 where you get tabs too often than the rand editor which *always*
 trashes tabs, even if they were in the original file.  The usual
 reasons for NOT wanting tabs are that you prefer non-equal tab
 settings, or that you use other programs which don't default right.)

To make vi not do tabs when you autoindent, do
	:set tabstop=0
This has the negative effect of displaying files with tabs in them a
bit weird (i.e. C programs.), but it means that vi will use spaces
instead of tabs to indent with.
	If your real complaint is that you don't like tab stops of size
8, you can set ts=4 sw=4 and then print your programs using options to
expand tabs by +4 (e.g. pr -e4 foo.c)

-- 
# Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs