LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to indent the file lines using vi (https://www.linuxquestions.org/questions/programming-9/how-to-indent-the-file-lines-using-vi-835741/)

paragkalra 10-01-2010 10:54 PM

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.

ghostdog74 10-01-2010 11:30 PM

eg, line 5 to 10
Code:

:5,10s/^/    /

dugan 10-01-2010 11:56 PM

If "vi" is an alias for "vim", then "gg=G" in command mode will work.

paragkalra 10-03-2010 09:46 PM

Quote:

:5,10s/^/ /
Thanks, it worked

grail 10-03-2010 09:58 PM

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'??

propofol 10-04-2010 12:49 AM

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


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