[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Padding Tabs with spaces in vi

Posted on 1997-05-16
11
Medium Priority
?
421 Views
Last Modified: 2006-11-17
null
0
Comment
Question by:myrddin7
11 Comments
 
LVL 2

Expert Comment

by:mlev
ID: 2006292
If you happen to use vim, you can :set expandtab
I don't think "plain" vi supports it.
0
 
LVL 5

Expert Comment

by:n0thing
ID: 2006293
Hi,

   In vi do:
      ":%s/<TAB>/number_of_space_here/g"

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

Regards,
n0thing

0
 

Author Comment

by:myrddin7
ID: 2006294
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:kljr
ID: 2006295
Hi,
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.

0
 

Author Comment

by:myrddin7
ID: 2006296
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).
0
 

Expert Comment

by:mesa
ID: 2006297
The easiest way to convert tabs to spaces is to pipe the text through unexpand:

1G!Gunexpand -a

0
 

Author Comment

by:myrddin7
ID: 2006298
I AM NOT LOOKING FOR A CONVERSION TECHNIQUE!!!!!!

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!
0
 
LVL 1

Expert Comment

by:sherwood
ID: 2006299
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.
0
 

Author Comment

by:myrddin7
ID: 2006300
Any way to withdrawn this question?
0
 

Author Comment

by:myrddin7
ID: 2006301
Edited text of question
0
 
LVL 4

Accepted Solution

by:
jos010697 earned 40 total points
ID: 2006302
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 jos@and.nl
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question