Solved

Padding Tabs with spaces in vi

Posted on 1997-05-16
11
396 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AIX Server 10 87
Using Grep to Find a file 8 93
How to Change Interface on Cisco IOU 11 101
Control Number of Log Files -Perl 7 74
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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…
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…
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…

821 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