Solved

Padding Tabs with spaces in vi

Posted on 1997-05-16
11
413 Views
Last Modified: 2006-11-17
null
0
Comment
Question by:myrddin7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 20 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

717 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