set tab to 4 spaces in vi | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

set tab to 4 spaces in vi

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-13-2009
pinnacle pinnacle is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 8 May 2014, 12:25 PM EDT
Posts: 242
Thanks: 9
Thanked 1 Time in 1 Post
set tab to 4 spaces in vi

Hi,
I want to set my tab lenght to 4 spaces instead of 8.
And when i press tab instead of inserting tab it should insert 4 spaces.
if i do

Code:
set ts=4

this set tab=4. But this inserts tab.
Say suppose i copy the code from unix to texpad/wordpad.Textpad will interpret tab as 8 spaces.(I can set tab space in textpad to 4 spaces but i cant tell everyone who copy my code to text pad to set their tab in textpad).
I would like a command that will insert 4 spaces when i press tab instead of inserting tab of length 4 in vi.
How to set tab to 4 spaces?
Appreciate help.
Sponsored Links
    #2  
Old 05-13-2009
ShawnMilo ShawnMilo is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 10 November 2009, 8:27 AM EST
Posts: 252
Thanks: 0
Thanked 1 Time in 1 Post

Code:
set expandtab

Also, set that in your .vimrc file for more convenience.

Here is what I use:


Code:
set nu
set tabstop=4
set shiftwidth=4
set autoindent
set expandtab

Sponsored Links
    #3  
Old 05-13-2009
mjd_tech mjd_tech is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 17 August 2009, 10:45 AM EDT
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Here's the settings from my .vimrc file

Code:
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab

I think this will do what you want.
    #4  
Old 05-13-2009
jwebb_2112 jwebb_2112 is offline
Registered User
 
Join Date: May 2009
Last Activity: 14 May 2009, 3:39 PM EDT
Location: Lehi, UT -- Just 30 miles south of Salt Lake City.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
It is the `set expandtab` setting that turns the tab from an actual tab into 4 spaces
Sponsored Links
    #5  
Old 05-13-2009
pinnacle pinnacle is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 8 May 2014, 12:25 PM EDT
Posts: 242
Thanks: 9
Thanked 1 Time in 1 Post
Quote:
Originally Posted by jwebb_2112 View Post
It is the `set expandtab` setting that turns the tab from an actual tab into 4 spaces

I dont have set expandtab in vi
Quote:
:set all
noautoindent nomodelines noshowmode
autoprint nonumber noslowopen
noautowrite nonovice tabstop=4
nobeautify nooptimize taglength=0
directory=/var/tmp paragraphs=IPLPPPQPP LIpplpipnpptags=tags /usr/lib/tags
noedcompatible prompt tagstack
noerrorbells noreadonly term=xterm
noexrc redraw noterse
flash remap timeout
hardtabs=8 report=5 ttytype=xterm
noignorecase scroll=20 warn
nolisp sections=NHSHH HUuhsh+c window=40
nolist shell=/bin/ksh wrapscan
magic shiftwidth=8 wrapmargin=0
mesg noshowmatch nowriteany
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tab spaces with sed handak9 UNIX for Dummies Questions & Answers 11 03-31-2009 04:32 PM
how to append spaces(say 10 spaces) at the end of each line based on the length of th prathima UNIX for Dummies Questions & Answers 17 01-28-2009 03:10 PM
Why am I getting spaces when there is none??!! Nomaad Shell Programming and Scripting 2 08-10-2006 06:33 PM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 01:24 PM
How to pad spaces sarahho Shell Programming and Scripting 3 09-30-2002 05:45 AM



All times are GMT -4. The time now is 07:54 PM.