LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-01-2010, 11:54 PM   #1
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Rep: Reputation: 31
How to indent the file lines using vi


Every now and then I have to indent the lines in my script to 4 space characters.

I generally do it line by line.

Is there an automated command in vi using which I can indent some set of lines to desired number of space characters in one go.
 
Old 10-02-2010, 12:30 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
eg, line 5 to 10
Code:
:5,10s/^/    /
 
Old 10-02-2010, 12:56 AM   #3
dugan
Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 5,005

Rep: Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560
If "vi" is an alias for "vim", then "gg=G" in command mode will work.
 
Old 10-03-2010, 10:46 PM   #4
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Original Poster
Rep: Reputation: 31
Quote:
:5,10s/^/ /
Thanks, it worked
 
Old 10-03-2010, 10:58 PM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Please mark as SOLVED once you have your solution

@dugan - tried your suggestion but instead of indenting it removed all indent from my file Even though at the bottom of the screen
it says '10 line indented'??

Last edited by grail; 10-03-2010 at 11:01 PM.
 
Old 10-04-2010, 01:49 AM   #6
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 299

Rep: Reputation: 55
You could also do:
Code:
:5,10>
or mark a block in command mode with "ma" at the start then "mb" at the end and do:
Code:
:'a,'b>
">>" indents the current line, while "5>>" indents 5 lines starting at the current position.

Regards,
Stefan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to copy some lines in a file and delete these lines after gartura Linux - General 1 07-20-2010 09:55 AM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 07:18 PM
replace several lines in a file with other lines in another file if condition yara Linux - General 12 10-27-2009 04:46 PM
Substitute specific lines with lines from another file rahmathullakm Programming 4 01-10-2009 06:47 AM
indent cpp file with emacs~ black Linux - Software 10 09-10-2004 01:43 AM


All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration