Padding Tabs with spaces in vi

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you happen to use vim, you can :set expandtab
I don't think "plain" vi supports it.

   In vi do:

   don't type the " character.
where <TAB> = TAB key.
   It'll find all the <TAB> and replace it with spaces in your


myrddin7Author Commented:
I know how to do a search and replace.  Sorry, that was not the question.

There are a number of options in vi that can be set up in the .exrc file, I wanted to know if there was an option to setup vi to pad all tabs with spaces.

The search and replace is just a work-around.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

To set the required number of spaces for tab, you have to use set options. For seting the tab use tabstop parameter.
In vi, at ESC mode use the following with the colon(:) as given below.
:set tabstop=5
to set the default tab to 5 spaces instead of 8 spaces. Here whatever the number you specify in the tabspace will act as tab.
The other way is create a ".exrc" file in your HOME directory which should contain the following lines as given below.
#cat $HOME/.exrc
set tabstop=5
This .exrc is the file which will initialise the vi parameters.
I think this should solve your purpose.

myrddin7Author Commented:
I can set the number of spaces a tab is translated to, but my question is not that.  My questions is how do I get that tab to be written to the file as X spaces where X is the number of spaces I have set for teh tab stop.

Sorry, no cigar.  I will increase the number of points, since this seems to be a toughie.  Maybe as has been suggested, there is no way to so it in vi, but only in vim (however, I do not have vim available for use).
The easiest way to convert tabs to spaces is to pipe the text through unexpand:

1G!Gunexpand -a

myrddin7Author Commented:

If I wanted that, as a computer programmer,  I could write that in a  hour.

I want to know if I can set vi to do it automatically!
You can't.
Best you can do is to define a macro that run's mesa's answer.

Or give details about your platform, and ask someone
to email you vim, or (I think) vile.

Or get the source to those programs and compile them for
your platform.

Or learn a new editor.
myrddin7Author Commented:
Any way to withdrawn this question?
myrddin7Author Commented:
Edited text of question
Oh my, oh my ;-) Where did the old unix philosophy go?
Doesn't anyone remember the funky '!' command in vi
anymore? Here's how I converted tabs to spaces
years ago (and still do it):

   1,$! expand

This simply pipes all text (line 1 thru line $) to the expand
command. Read the man pages for 'expand' and you'll
get the picture (hint: it expands tabs the way you want
them to be expanded ;-)

kind regards,

Jos aka

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.