LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 10: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-01-2010, 11:30 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
eg, line 5 to 10
Code:
:5,10s/^/    /
 
Old 10-01-2010, 11:56 PM   #3
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,562

Rep: Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394
If "vi" is an alias for "vim", then "gg=G" in command mode will work.
 
Old 10-03-2010, 09: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, 09:58 PM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,431

Rep: Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878
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 10:01 PM.
 
Old 10-04-2010, 12:49 AM   #6
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 260

Rep: Reputation: 50
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 08:55 AM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 06:18 PM
replace several lines in a file with other lines in another file if condition yara Linux - General 12 10-27-2009 03:46 PM
Substitute specific lines with lines from another file rahmathullakm Programming 4 01-10-2009 05:47 AM
indent cpp file with emacs~ black Linux - Software 10 09-10-2004 12:43 AM


All times are GMT -5. The time now is 11:31 AM.

Main Menu
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