For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > October 2007 > VI editor question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author VI editor question
Amy

2007-10-18, 7:09 pm

Hi,

Could anyone teach me how to indent multiple lines at once? Say there are
10 lines that all begin at column 1, is there one command to indent all 10
lines to begin at column 4?

Thank you very much in advance. I appreciate your time.

Best,
Amy


Bin Chen

2007-10-18, 7:09 pm

On 10 19 , 6 20 , "Amy" <the_orch...@yahoo.com> wrote:
> Hi,
>
> Could anyone teach me how to indent multiple lines at once? Say there are
> 10 lines that all begin at column 1, is there one command to indent all 10
> lines to begin at column 4?
>

Select all the lines using visual mode by press 'v', then move the
cursor. After you selected all the line you desired, press '=' to
indent.
> Thank you very much in advance. I appreciate your time.
>
> Best,
> Amy



Logan Shaw

2007-10-18, 10:10 pm

Amy wrote:
> Could anyone teach me how to indent multiple lines at once? Say there are
> 10 lines that all begin at column 1, is there one command to indent all 10
> lines to begin at column 4?


First step, set vi up for multiples of 3 columns:

:set shiftwidth=3

Follow that with by hitting "return". (You can abbreviate "shiftwidth"
to just "sw" if you want.)

Second step, go to the last line of the block and set a mark called "a"
there. You do this by going there (with j or k) and then typing "ma".

Third step, go to the beginning and ask vi to right indent from the current
position to the mark by typing ">'a". Broken down into its components, the
first part (">") says "indent from here to..." and the second part says
"the position I marked as 'a'".

Alternate method: set the shiftwidth, go to the first line, and type "10>>".
The "10" says "repeat the following command 10 times", and the ">>" says
"indent one line of text".

Final method: type ":.,+9s/^/ /" and hit enter. That says to apply the
"s" (substitution) operator to the range "." (current line) through "+9"
(nine lines below current line), and it substitutes 3 spaces ("/ /")
for the empty string occurring at the beginning of line ("/^/").

Note that the first 2 methods work with tabs and adjust the indentation
appropriately, whereas the last method just blindly inserts 3 spaces
regardless of whether the line starts with a tab character or whatever.

- Logan
hymie!

2007-10-19, 7:09 pm

In our last episode, the evil Dr. Lacto had captured our hero,
"Amy" <the_orchidz@yahoo.com>, who said:

>Could anyone teach me how to indent multiple lines at once? Say there are
>10 lines that all begin at column 1, is there one command to indent all 10
>lines to begin at column 4?


:%s/^/ /

--hymie! http://lactose.homelinux.net/~hymie hymie@lactose.homelinux.net
------------------------ Without caffeine for 353 days ------------------------
Gary R. Schmidt

2007-10-19, 7:09 pm

hymie! wrote:
> In our last episode, the evil Dr. Lacto had captured our hero,
> "Amy" <the_orchidz@yahoo.com>, who said:
>
>
> :%s/^/ /
>

Well, that does *all* of the lines.

:.,.+10s/^/ /

does just the next 10.

As does
:set sw=4
10>>

Cheers,
Gary B-)

--
________________________________________
______________________________________
Armful of chairs: Something some people would not know
whether you were up them with or not
- Barry Humphries
Amy

2007-10-19, 7:09 pm

Thank you for everyone's help. It's good to know different methods. I
really appreciate it.
Amy

"Gary R. Schmidt" <grschmidt@acm.org> wrote in message
news:j7rmu4-0g2.ln1@paranoia.mcleod-schmidt.id.au...
> hymie! wrote:
> Well, that does *all* of the lines.
>
> :.,.+10s/^/ /
>
> does just the next 10.
>
> As does
> :set sw=4
> 10>>
>
> Cheers,
> Gary B-)
>
> --
> ________________________________________
______________________________________
> Armful of chairs: Something some people would not know
> whether you were up them with or not
> - Barry Humphries



Michael Zawrotny

2007-10-19, 7:09 pm

Amy,

On Thu, 18 Oct 2007 15:20:52 -0700, Amy <the_orchidz@yahoo.com> wrote:
>
> Could anyone teach me how to indent multiple lines at once? Say there are
> 10 lines that all begin at column 1, is there one command to indent all 10
> lines to begin at column 4?


My preferred method is to go to the first line in the paragraph (or
the blank line above it, and ">}". The ">" is indent as others have
pointed out, and "}" means move to the end of the paragraph. You
could likewise start at the bottom and "y{", but for some reason I
never do that.


Mike

--
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University | email: zawrotny@sb.fsu.edu
Tallahassee, FL 32306-4380 | phone: (850) 644-0069
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com