VI editor question - Unix

This is a discussion on VI editor question - Unix ; 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 ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: VI editor question

  1. VI editor question

    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



  2. Re: VI editor question

    On 10 19 , 6 20 , "Amy" 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




  3. Re: VI editor question

    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

  4. Re: VI editor question

    In our last episode, the evil Dr. Lacto had captured our hero,
    "Amy" , 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 ------------------------

  5. Re: VI editor question

    hymie! wrote:
    > In our last episode, the evil Dr. Lacto had captured our hero,
    > "Amy" , 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/^/ /
    >

    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

  6. Re: VI editor question

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

    "Gary R. Schmidt" wrote in message
    news:j7rmu4-0g2.ln1@paranoia.mcleod-schmidt.id.au...
    > hymie! wrote:
    >> In our last episode, the evil Dr. Lacto had captured our hero,
    >> "Amy" , 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/^/ /
    >>

    > 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




  7. Re: VI editor question

    Amy,

    On Thu, 18 Oct 2007 15:20:52 -0700, 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?


    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

+ Reply to Thread