How Do You Indent a Block of Lines in vi The Same Amount?

Problem scenario
You want several lines to be indented by four more spaces automatically.  You do not want to do it manually line-by-line.  How do you indent multiple lines uniformly with the same number of spaces (regardless if they are indented similarly or dissimilarly)?

Solution
1.  Open the file in vi.
2.  Enter this command and press enter afterwards (but replace "4" with the number of spaces you want in your indentation):    :set shiftwidth=4
3.  Go to the highest line that you want indented.
4.  Press the "v" key
5.  Highlight the lines you want indented by pressing the down key.  Once all the lines are highlighted, go to the next step.
6.  Press the ">" key.  (On most keyboards it is pressed by holding shift and pressing the "." (period) key.  (To unindent, reverse indent, or shift to the the left, use the "<" key.)

Leave a comment

Your email address will not be published. Required fields are marked *