Solved

Padding Tabs with spaces in vi

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

Expert Comment

by:mlev
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Expert Comment

by:kljr
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

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

1G!Gunexpand -a

0
 

Author Comment

by:myrddin7
Comment Utility
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
Comment Utility
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
Comment Utility
Any way to withdrawn this question?
0
 

Author Comment

by:myrddin7
Comment Utility
Edited text of question
0
 
LVL 4

Accepted Solution

by:
jos010697 earned 20 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now