Solved

Padding Tabs with spaces in vi

Posted on 1997-05-16
11
403 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Suggested Solutions

Title # Comments Views Activity
Unix/bash: scripted arithmetic 13 101
MarkLogic 1 89
to update from RHEL 6.0 to 6.8 anything needed other than "yum update"? 7 109
awk sed 8 65
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.
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.

856 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